【发布时间】:2018-10-21 15:18:05
【问题描述】:
我有一个 SystemJS 项目。我使用 NGC 和 Rollup 进行 AOT 编译。一切正常,但用于路由的延迟加载不起作用。 例如,这是我的 tsconfig-aot.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"baseUrl": ".",
"paths": {
"app/*": [ "../src/app/*" ]
}
},
"typeRoots": [
"node_modules/@types"
],
"files": [
"../src/app/app.module.aot.ts"
],
"exclude": [
"node_modules",
"typings"
],
"angularCompilerOptions": {
"genDir": "../",
"skipMetadataEmit": false,
"skipTemplateCodegen": false
}
}
和rollup.config.app.js
'use strict';
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: './src/app/app.module.aot.js',
dest: './src/dist/app.module.min.js',
sourceMap: true,
format: 'iife',
onwarn: function(warning) {
// Skip certain warnings
if ( warning.message.indexOf('\'default\' is not exported by rollup') === -1) { return; }
if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
if ( warning.code === 'EVAL' ) { return; }
console.warn( warning.message );
},
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: [
'./node_modules/rxjs/**'
]
}),
uglify()
]
}
使用汇总运行 AOT 后一切正常,但当我尝试对我的应用使用延迟加载时,它不起作用。
const routes: Routes = [
{
path: "test/:id",
loadChildren: "./src/app/app.module#TestModule"
}
];
AOT 构建通过没有任何错误,在使用 AOT 运行应用程序后,我在开发工具中看不到任何错误。但是延迟加载也不起作用。
UPD 在 JIT 编译中,延迟加载一切正常。
知道如何解决这个问题吗?
【问题讨论】:
-
Angular AOT 不适用于
Rollup。为什么不迁移到 webpack? -
@RitwickDey 我不能在 web pack 上移动这个项目,因为它是一个非常大的带有 asp.net 的应用程序。此外,带有 Rollup 的 AOT 工作正常,但lazyload 不起作用。所有其他的东西看起来都不错。您对如何解决此问题有任何想法吗?
-
据我所知,AOT 不适用于
rollup。你可以查看这个站点dzurico.com/angular-aot-webpack-lazy-loading ......这个站点正在展示如何使用 Webpack 做同样的事情(几乎相同的配置 - 试一试) -
@RitwickDey 有趣的是,我花了更多时间来配置 Rollup 和 AOT (NGC),它对我有用,我希望 :) 我会尝试从 System.js 转移到网络包。另外,我认为有人可以知道如何在 System.js 上做到这一点
标签: angular lazy-loading angular-routing angular2-aot rollup