我有一个可用的 Angular2 应用程序,其结构如下:
/app
/components
/moduleA
/moduleB
/...
/shared
app.module.ts
app.routing.ts
app.component.ts
main.ts
现在,我使用 systemjs-builder 在我的 gulp 文件中创建一个包含所有打字稿的单个文件:
gulp.task('bundle', () => {
builder.buildStatic('app/*.js', 'web/bundle.app.js')
.then(function() {
console.log('Build complete');
})
})
然后在我的应用程序的 index.html 中:
<body>
<app>Loading...</app>
<!-- application bundle -->
<script src="bundle.app.js"></script>
</body>
现在一切正常,但我的应用程序正在增长为多个模块,我想将其拆分为不同的模块文件,因此我将common.js用于/app/shared模块,而不是bundle.app.js,然后/app/components 内的所有其他模块的 moduleA.js、moduleB.js 等。
这可以用 systemjs-builder 来完成吗?这必须是一个非常常见的功能,但我在文档中看不到任何内容。
EDIT:我设法创建了一些像这样的包
gulp.task('bundle', () => {
builder.buildStatic('app/*.js - app/components/**/*.js', 'web/common.js')
.then(function() {
console.log('Build complete');
});
builder.bundle('app/components/moduleA/**/*.js', 'web/moduleA.js');
builder.bundle('app/components/moduleB/**/*.js', 'web/moduleB.js');
})
但我不认为这完全没问题;我以前的单个包是 2,267KB,现在我的 3 个模块是 785KB (common.js) + 2,567KB (moduleA.js) + 1,530KB (moduleB.js),这没有意义。
如果我检查 moduleS 和模块包内的代码,我可以看到 Angular2 模块以及只应在 common.js 中的内容