Angular 2如何加载具有子依赖关系angular-cli的第三方供应商节点模块

时间:2016-06-27 14:46:18

标签: node.js angular npm node-modules angular-cli

在Angular 2中加载single node module一个angular-cli引导项目在wiki中很好地描述了。只是好奇,如何在一个用angular-cli引导的项目中很好地加载一个更复杂的节点模块?

E.g。 angular2-apollo依赖于几个子依赖,如apollo-client,graphql,lodash,......

我将节点模块添加到angular-cli-build.js

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      '...', 
      'angular2-apollo/**'
    ]
  });
};

使用

注册节点模块ins system-config.js
const barrels: string[] = [
  // ...
  // Thirdparty barrels.
  'rxjs',
  'angular2-apollo',

  // App specific barrels.
  // ...
];

// ...

// Apply the CLI SystemJS configuration.
System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'angular2-apollo':'vendor/angular2-apollo/build/src',

    'main': 'main.js',
  },
  packages: cliSystemConfigPackages
});

然而,这只是加载angular2-apollo。 angular2-apollo的子依赖性没有得到加载。如何在angular-cli bootstraped项目中加载system.js的子依赖项?

2 个答案:

答案 0 :(得分:5)

So, you are facing a really annoying problem with System.js and there is an open issue about that on the Angular CLI here: https://github.com/angular/angular-cli/issues/882

It basically means you have to specify all the dependencies in the system.config.ts file and load them all in the angular-cli-build.js file.... horrible I know...

Maybe in the future that will happen: https://github.com/angular/angular-cli/issues/909

But, until the Angular CLI will become better, here is a starter app that includes Angular 2.0 and angular2-apollo with all it's dependencies (and even with a mock GraphQL server..) - https://github.com/Urigo/apollo-ship

You can check out the system.config.ts and the angular-cli-build.js in there to see how to include dependencies on angular2-apollo, apollo-client, lodash (and all the wanted dependencies of it), redux and many many more (too many....)

答案 1 :(得分:2)

我认为你在system.config.ts中做错了。用户包配置应位于此文件的上半部分。

Console.WriteLine(dalist[2].Contains('-'));

看看它对你有帮助吗?