我正在尝试找出一种方法,将 Angular 2 node_modules 文件夹中所需的所有内容编译到一个文件中。当我的网站加载时,似乎有大量的 http 调用,这肯定不是最佳的,或者新的和改进的 Angular 的推荐流程..
我不关心我自己的 typescript 文件,因为我知道如何处理它们,但是你连接node_modules文件等的方法是什么?
最佳答案
如果您使用SystemJS
1. package.json
:将这些添加到 devDependencies
"devDependencies": {
"gulp": "^3.9.1",
"systemjs-builder": "^0.15.16"
}
2.执行npm install
3.在index.html
同一级别创建gulpfile.js,并在其中包含此内容
var gulp = require('gulp'),
Builder = require('systemjs-builder');
gulp.task('bundle-angular-dependencies', function() {
// optional constructor options
// sets the baseURL and loads the configuration file
var builder = new Builder('', 'systemjs.config.js');
return builder
.bundle('app/boot.js - [app/**/*.js]', 'path/to/put/angular.bundle.js', { minify: true})
.then(function() {
console.log('Build complete');
})
.catch(function(err) {
console.log('Build error');
console.log(err);
});
});
4. 打开终端并转到您的项目目录。执行gulpbundle-Angular-dependencies
5. 在 index.html
中引用 angular.bundle.js
,位于 system.js
下方,但是上面的system.config.js
。
如果您有任何疑问,请告诉我。
关于angular - 将 Angular 2 node_modules 文件编译为一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37488632/