如何通过 angular-cli 使用 AMD?
How to use AMD with angular-cli?
我正在尝试将我现有的 angular 2 项目移动到 angular-cli。我目前的脚手架使用 Webpack,我经常使用 AMD 来仅在某些异步组件中加载某些 js 文件。
例如:
require(['json-fn'], (JSONfn) => {
srvc.JSONfn = JSONfn;
});
新的 angular-cli 脚手架给出了以下错误:
Cannot find name 'require'.
webpack 编译失败。我该怎么办?
angular-cli使用webpack 2构建项目,支持AMD,但是需要使用import
语句:
import * as jsonFn from 'json-fn';
// ..
ngOnInit() {
// use it normally here
jsonFn.parse();
}
我正在尝试将我现有的 angular 2 项目移动到 angular-cli。我目前的脚手架使用 Webpack,我经常使用 AMD 来仅在某些异步组件中加载某些 js 文件。 例如:
require(['json-fn'], (JSONfn) => {
srvc.JSONfn = JSONfn;
});
新的 angular-cli 脚手架给出了以下错误:
Cannot find name 'require'.
webpack 编译失败。我该怎么办?
angular-cli使用webpack 2构建项目,支持AMD,但是需要使用import
语句:
import * as jsonFn from 'json-fn';
// ..
ngOnInit() {
// use it normally here
jsonFn.parse();
}