为什么ngc + Rollup bundled Angular 2 RC.6路由失败?

Why does ngc + Rollup bundled Angular 2 RC.6 routing fail?

我正在尝试利用 RC.6 中可用的新 AOT 编译,但 运行 成为障碍。我可以使用 ngc => Rollup => Babel 成功创建一个包,但是每次我 运行 Rollup 我都会收到多个警告:

The 'this' keyword is equivalent to未定义at the top level of an ES module, and has been rewritten

捆绑成功完成。相同的代码库适用于 JIT 编译。 Angular 2 应用程序启动速度很快,但是每次我尝试导航到 root 以外的另一条路线时,我都会收到此错误:

```

bundle.js:2781 EXCEPTION: Uncaught (in promise): EmptyError: no elements in    sequenceErrorHandler.handleError @ bundle.js:2781
bundle.js:2781 ORIGINAL STACKTRACE:ErrorHandler.handleError @ bundle.js:2781
bundle.js:2781 Error: Uncaught (in promise): EmptyError: no elements in sequence
    at resolvePromise (zone.js:558)
    at zone.js:535
    at ZoneDelegate.invoke (zone.js:332)
    at Object.onInvoke (bundle.js:3549)
    at ZoneDelegate.invoke (zone.js:331)
    at Zone.run (zone.js:225)
    at zone.js:591
    at ZoneDelegate.invokeTask (zone.js:365)
    at Object.onInvokeTask (bundle.js:3549)
    at ZoneDelegate.invokeTask (zone.js:364)ErrorHandler.handleError @ bundle.js:2781
zone.js:484 Unhandled Promise rejection: no elements in sequence ; Zone: angular ; Task: Promise.then ; Value: Error: no elements in sequence
    at new EmptyError (bundle.js:7019)
    at FirstSubscriber._complete (bundle.js:7071)
    at FirstSubscriber.complete (bundle.js:3410)
    at MergeAllSubscriber._complete (bundle.js:6854)
    at MergeAllSubscriber.complete (bundle.js:3410)
    at MapSubscriber._complete (bundle.js:3410)
    at MapSubscriber.complete (bundle.js:3410)
    at EmptyObservable._subscribe (bundle.js:6598)
    at EmptyObservable.subscribe (bundle.js:3441)
    at Observable.subscribe (bundle.js:3441) EmptyError: no elements in sequence
    at new EmptyError (http://localhost:4200/bundle.js:7019:243)
    at FirstSubscriber._complete (http://localhost:4200/bundle.js:7071:1680)
    at FirstSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at MergeAllSubscriber._complete (http://localhost:4200/bundle.js:6854:783)
    at MergeAllSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at MapSubscriber._complete (http://localhost:4200/bundle.js:3410:547)
    at MapSubscriber.complete (http://localhost:4200/bundle.js:3410:99)
    at EmptyObservable._subscribe (http://localhost:4200/bundle.js:6598:234)
    at EmptyObservable.subscribe (http://localhost:4200/bundle.js:3441:223)
    at Observable.subscribe (http://localhost:4200/bundle.js:3441:187)consoleError @ zone.js:484
zone.js:486 Error: Uncaught (in promise): EmptyError: no elements in sequence
    at resolvePromise (zone.js:558)
    at zone.js:535
    at ZoneDelegate.invoke (zone.js:332)
    at Object.onInvoke (bundle.js:3549)
    at ZoneDelegate.invoke (zone.js:331)
    at Zone.run (zone.js:225)
    at zone.js:591
    at ZoneDelegate.invokeTask (zone.js:365)
    at Object.onInvokeTask (bundle.js:3549)
    at ZoneDelegate.invokeTask (zone.js:364)

```

ngc 编译时没有任何警告或错误。

我的rollup.config.js如下:

```

// rollup.config.js
import alias from 'rollup-plugin-alias';
import resolve from 'rollup-plugin-node-resolve';


export default {
  entry: 'main.js',
  format: 'iife',
  dest: 'dist/bundle.es2015.js',
  sourceMap: false,
  plugins: [
    alias({ rxjs: __dirname + '/node_modules/rxjs-es' }),
    resolve({ module: true })
  ]
}

```

当使用 Babel 将 ES2015 包转译为 ES5 时,我收到以下警告:

[BABEL] Note: The code generator has deoptimised the styling of "./dist/bundle.es2015.js" as it exceeds the max of "100KB".

可能是什么问题?

此致, 史蒂夫

我无法让 Babel 6.5.2 正确转译包。在 Rob Wormald 的建议下,我尝试使用 Closure Compiler 转译 Rollup 的 ES2015 包输出并且它成功了。似乎只有 Java 版本是稳定的,但是当 JS 版本 运行 顺利时,我打算将它与我的 rollup.config.js 集成。现在,我通过 npm 脚本中的一系列异步回调来处理构建。

https://github.com/steveblue/angular2-rollup

https://developers.google.com/closure/compiler