【发布时间】:2016-03-21 14:36:57
【问题描述】:
对于整个 SystemJS 来说有点新意,所以我可能会完全了解它文档中的重要部分。我对使用 Browserify 捆绑东西非常熟悉,但是在部署时,整个 SystemJS 让我摸不着头脑。没有双关语,因为我喜欢 SystemJS。
鉴于以下配置文件具有与 Angular2 5 分钟快速入门相同的配置:
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script src="app.config.js"></script>
<script>
System.import('app/main')
.then(null, console.error.bind(console));
</script>
我的 Gulpfile 中使用 SystemJS Builder 的以下内容:
gulp.task('system-builder', function (cb) {
var builder = new Builder('./production/public/', './production/public/app.config.js');
fs.copy('./client/node_modules', './production/public/node_modules', function(err) {
builder.bundle('./production/public/js/app/app.boot.js', './production/public/js/app/app.js')
.then(function() {
console.log('Build complete');
cb();
})
.catch(function(err) {
console.log('Build error');
console.log(err);
});
});
});
我现在有一个 app.js 文件。回到 HTML 文件,如何在捆绑状态下使用应用程序代码?因为在进行以下更新时出现angular2-polyfills.js:322 Error: SyntaxError: Unexpected identifier 错误。请注意,我已将 app.config.js 替换为 /js/app/app.js:
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script src="/js/app/app.js"></script>
<script>
System.import('/js/app/app.boot').then(null, console.error.bind(console));
</script>
我在使用 JSPM 时看到了一百万次点击,但在决定使用更多库之前,我想知道 SystemJS 是如何本地处理这个问题的。
【问题讨论】: