我有一个angular2应用程序。我使用以下配置捆绑应用程序。我拥有 lib 文件夹下的所有库,并捆绑到 js 文件夹。
const Builder = require('systemjs-builder');
gulp.task('build-minify-angular', function () {
var builder = new Builder();
builder.reset();
builder.loader.defaultJSExtensions = true;
builder.config({
packages: {
'rxjs': {
main: 'rxjs/rx',
defaultExtension: 'js'
}
},
map: {
'myapp': "myapp/app.js",
'@angular/core': '@angular/core/bundles/core.umd.js',
'@angular/common': '@angular/common/bundles/common.umd.js',
'@angular/compiler': '@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': '@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': '@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': '@angular/http/bundles/http.umd.js',
'@angular/router': '@angular/router/bundles/router.umd.js',
'@angular/forms': '@angular/forms/bundles/forms.umd.js',
'@ng-bootstrap/ng-bootstrap': '@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
},
baseURL: 'wwwroot/lib'
});
builder.bundle('myapp', 'wwwroot/js/bundle.js', { minify: true });
});
```
The app works fine if I have the following configuration.
window.onload = () => {
System.config({
packages: {
'myapp': {
main: 'app', defaultExtension: 'js'
},
'': {
defaultExtension: 'js'
}
},
map: {
'rxjs': '../../js/rxjs/',
'@@angular/core': '../../js/@@angular/core/bundles/core.umd.min.js',
'@@angular/common': '../../js/@@angular/common/bundles/common.umd.min.js',
'@@angular/compiler': '../../js/@@angular/compiler/bundles/compiler.umd.min.js',
'@@angular/platform-browser': '../../js/@@angular/platform-browser/bundles/platform-browser.umd.min.js',
'@@angular/platform-browser-dynamic': '../../js/@@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js',
'@@angular/http': '../../js/@@angular/http/bundles/http.umd.min.js',
'@@angular/router': '../../js/@@angular/router/bundles/router.umd.min.js',
'@@angular/forms': '../../js/@@angular/forms/bundles/forms.umd.min.js',
'@@ng-bootstrap/ng-bootstrap': '../../js/@@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
}
});
System.import("myapp");
}
如果我从配置中移除地图,该应用无效。
我希望 systemjs-builder 将 myapp 和所有角度库捆绑在一个 bundle.js 文件中。但事实并非如此,并在各种包文件夹中寻找包。
如何将 myapp 及其依赖项捆绑在一个文件中?
答案 0 :(得分:1)
更改
builder.bundle('myapp', 'wwwroot/js/bundle.js', { minify: true });
是
builder.buildStatic('myapp', 'wwwroot/js/bundle.js', { minify: true });
这将构建一个可以包含在index.html页面上的单个自执行文件