angular 2 - adding 3rd party libs

后端 未结 8 1856
盖世英雄少女心
盖世英雄少女心 2020-11-28 09:22

I am trying to start using angular 2 cli.
I want to use momentjs in my project so here is what I have done:
1. created project using angular cli.
2. run np

8条回答
  •  一向
    一向 (楼主)
    2020-11-28 09:57

    Example.. First we need to install ChartJS from npm.

    npm install chart.js --save
    

    Now that we have installed ChartJS we need to tell the CLI in the angular-cli-build.js file where the new JavaScript file is located so it can be bundled.

    var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
    
    module.exports = function(defaults) {
      return new Angular2App(defaults, {
        vendorNpmFiles: [
          'systemjs/dist/system-polyfills.js',
          'systemjs/dist/system.src.js',
          'zone.js/dist/**/*.+(js|js.map)',
          'es6-shim/es6-shim.js',
          'reflect-metadata/**/*.+(js|js.map)',
          'rxjs/**/*.+(js|js.map)',
          '@angular/**/*.+(js|js.map)',
          'chart.js/Chart.min.js',
        ]
      });
    };
    
    
    const map: any = {
      'chartjs': 'vendor/chart.js/'
    };
    
    
    const packages: any = {
      chartjs: { defaultExtension: 'js', main: 'Chart.min.js' }
    };
    

提交回复
热议问题