SystemJS Builder,Bundle without Angular 2 for Lazy Loading
SystemJS Builder, Bundle without Angular2 for Lazyloading
我正在尝试将我的应用程序与 systemjs 构建器捆绑在一起。它是一个 "core" 应用程序,其中包含 angular2。然后将其他组件延迟加载到核心中。目前我正在捆绑我的核心,它可以工作,但是其他组件然后得到 404,因为它们正在搜索 angular2 的旧路径。
我想捆绑组件,但没有 angular2,组件就会使用我核心中的组件。我想我正在为此使用 buildStatic 吗?我只是把ts文件编译成js。
我试过的一些片段:
构建有效的核心:
gulp.task('bundle:js', function() {
var builder = new SystemBuilder('dist', './src/systemjs.config.js');
return builder.buildStatic('app', 'dist/app.js');
});
在我的 index.html 中,我正在加载 app.js 文件。现在大约是 2MB。
那么懒加载组件正在搜索:
https://IP/@angular/router-deprecated 结果为 404。
现在进入 "hard" 部分:
gulp.task('build:static', function () {
var builder = new SystemBuilder('', './dist/systemjs.config.js');
builder.buildStatic('dist/start.component.js', 'dist/start.component.static.js', {
defaultExtension: 'js',
globalName: 'test',
globalDeps: {
'@angular': '@angular'
}
});
});
在此之后我得到一个大约 1,1MB 的 JS 文件。所以我觉得里面没有angular2?
如果我现在尝试启动我的应用程序,它会告诉我:
EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on StartComponent
我的 StartComponent 中有一个指令。我的错是什么?这甚至可能是我的做法吗?
谢谢!
我需要使用 "system.bundle()" 才能正常工作。
我正在尝试将我的应用程序与 systemjs 构建器捆绑在一起。它是一个 "core" 应用程序,其中包含 angular2。然后将其他组件延迟加载到核心中。目前我正在捆绑我的核心,它可以工作,但是其他组件然后得到 404,因为它们正在搜索 angular2 的旧路径。
我想捆绑组件,但没有 angular2,组件就会使用我核心中的组件。我想我正在为此使用 buildStatic 吗?我只是把ts文件编译成js。
我试过的一些片段:
构建有效的核心:
gulp.task('bundle:js', function() {
var builder = new SystemBuilder('dist', './src/systemjs.config.js');
return builder.buildStatic('app', 'dist/app.js');
});
在我的 index.html 中,我正在加载 app.js 文件。现在大约是 2MB。
那么懒加载组件正在搜索: https://IP/@angular/router-deprecated 结果为 404。
现在进入 "hard" 部分:
gulp.task('build:static', function () {
var builder = new SystemBuilder('', './dist/systemjs.config.js');
builder.buildStatic('dist/start.component.js', 'dist/start.component.static.js', {
defaultExtension: 'js',
globalName: 'test',
globalDeps: {
'@angular': '@angular'
}
});
});
在此之后我得到一个大约 1,1MB 的 JS 文件。所以我觉得里面没有angular2?
如果我现在尝试启动我的应用程序,它会告诉我:
EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on StartComponent
我的 StartComponent 中有一个指令。我的错是什么?这甚至可能是我的做法吗?
谢谢!
我需要使用 "system.bundle()" 才能正常工作。