angular - **build --prod** 时延迟加载不起作用
问题描述
> app-routing.module.ts
const routes: Routes = [
{ path: '', redirectTo: 'test', pathMatch: 'full' },
{
path: 'test',
loadChildren: () => import('./test-lazy-loading/test-lazy-loading.module').then(m => m.TestLazyLoadingModule)
}
];
ERROR
GET http://localhost/styles.09e2c710755c8867a460.css net::ERR_ABORTED 404 (Not Found)
2localhost/:12 GET http://localhost/runtime-es2015.eb2b81c6532ef7a6ad37.js net::ERR_ABORTED 404 (Not Found)
它在运行ng serve时工作,但在构建ng build --prod时它不工作。请帮我!谢谢
解决方案
我到处寻找,但没有找到比禁用aot(Ahead Of Time)编译更好的解决方案。跑步ng build --prod --aot=false --build-optimizer=false
可以解决问题。您也可以禁用aotangular.json
{
"projects":{
"<your-project-name>":{
"architect":{
"build":{
"configurations":{
"configurations":{
"production":{
"aot":false
}
}
}
}
}
}
}
}
aot 和 jit(及时)之间的区别在于模块是在 jit 中动态编译的,就像在开发模式下使用ng serve
. 这会加快编译速度,但可能会影响您在生产中的性能。
当时aot似乎不支持aot或loadchildren。
推荐阅读
- sql-server - SQl Server 2017 - 可用性组和特殊表“复制”到仓库?
- node.js - Node js (multer) req.file 和 req.files 在 react js 中总是未定义,但在模板引擎中工作正常
- swift - 如何防止在 api 更改时解码/编码丢失密钥?
- php - 如何解决 PHP For 循环 INF 内存问题
- python - 基于部分匹配的国家名称连接两个数据框
- python - Python和Matlab对矩阵的功率显示相同矩阵的不同输出
- javascript - 按下后退按钮重置所有变量反应原生
- python - 我应该使用什么类型的服务器?
- apache-flink - 将 Flink 工作负载拆分到多个作业时如何避免冗余 IO 和反序列化
- windows - PSReadLine 历史不加载