【发布时间】:2016-10-29 15:30:21
【问题描述】:
在 Angular 2 中加载一个 single node module 一个 angular-cli 引导项目在 wiki 中有很好的描述。只是好奇,如何在使用 angular-cli 引导的项目中很好地加载更复杂的节点模块?
例如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/**'
]
});
};
并在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 引导项目中使用 system.js 加载子依赖项?
【问题讨论】:
-
可以将其移入
src/app/node_modules/并像其他TS 文件一样导入。 -
在我看来这不是正确的方法
标签: node.js angular npm node-modules angular-cli