【问题标题】:SystemJS Builder, Bundle without Angular2 for LazyloadingSystemJS Builder,不带 Angular 2 的捆绑包,用于延迟加载
【发布时间】:2016-07-15 09:59:40
【问题描述】:

我正在尝试将我的应用程序与 systemjs builder 捆绑在一起。它是一个“核心”应用程序,其中包含 angular2。然后将其他组件延迟加载到核心中。目前我捆绑了我的核心,它可以工作,但其他组件然后得到 404,因为它们正在搜索 angular2 的旧路径。

我想捆绑组件,但没有 angular2,然后组件使用我核心中的组件。我认为我正在为此使用 buildStatic?我只是把ts文件编译成js。

我尝试过的一些 sn-ps:

构建有效的核心:

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。

现在到“硬”部分:

   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 中有一个指令。我的错是什么?这甚至可能是我的做法吗?

谢谢!

【问题讨论】:

  • 使用了 builder.bundle() 然后它工作了。

标签: angular lazy-loading systemjs


【解决方案1】:

我需要使用“system.bundle()”来让它工作。

【讨论】:

  • 嗨,@Mamas,您愿意再解释一下吗?我面临着类似的问题,我不知道如何解决它。为什么 build.bundle() 可以解决您的问题?我在stackoverflow中也有一个问题stackoverflow.com/questions/38944257/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
  • 2016-05-23
  • 1970-01-01
相关资源
最近更新 更多