Angular 从 node_modules 延迟加载
Angular Lazy loading from node_modules
我将我的项目拆分为多个 Git 存储库,现在我遇到延迟加载问题
如果我使用以下语法将源代码从子仓库复制到主仓库
{
path: 'child-app',
loadChildren: './shared/child/src/app/child-app.module#ChildAppModule'
},
我可以毫无问题地构建和服务我的项目
但是,如果我将路线更改为指向 node_modules,如下所示
{
path: 'child-app',
loadChildren: '@mine/child/src/app/child-app.module#ChildAppModule'
},
或
{
path: 'child-app',
loadChildren: '../../node_modules/@mine/child/src/app/child-app.module#ChildAppModule'
},
它会引发这个错误:
ERROR in ./src/$$_gendir lazy
Module not found: Error: Can't resolve '/Users/myuser/Projects/web-app
/src/node_modules/@mine/child/src/app/child-app.module.module.ngfact
ory.ts' in '/Users/myuser/Projects/web-app/src/$$_gendir'
@ ./src/$$_gendir lazy
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.browser.ts
@ multi ./src/main.browser.ts webpack-hot-middleware/client?path=/__webpa
ck_hmr&timeout=2000&reload=true&noInfo=true
我正在使用 webpack 2 和 ngtools/webpack 来编译我的项目
使用 JIT 从 node_modules 延迟加载模块工作正常,但使用 AOT 延迟加载无效
github.com/angular/angular-cli/issues/5986
我找到的最佳解决方案是创建一个从 src/app/something 到 node_modules/something
的符号链接
ln -s source destination
它运行良好:)
我将我的项目拆分为多个 Git 存储库,现在我遇到延迟加载问题
如果我使用以下语法将源代码从子仓库复制到主仓库
{
path: 'child-app',
loadChildren: './shared/child/src/app/child-app.module#ChildAppModule'
},
我可以毫无问题地构建和服务我的项目 但是,如果我将路线更改为指向 node_modules,如下所示
{
path: 'child-app',
loadChildren: '@mine/child/src/app/child-app.module#ChildAppModule'
},
或
{
path: 'child-app',
loadChildren: '../../node_modules/@mine/child/src/app/child-app.module#ChildAppModule'
},
它会引发这个错误:
ERROR in ./src/$$_gendir lazy
Module not found: Error: Can't resolve '/Users/myuser/Projects/web-app
/src/node_modules/@mine/child/src/app/child-app.module.module.ngfact
ory.ts' in '/Users/myuser/Projects/web-app/src/$$_gendir'
@ ./src/$$_gendir lazy
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.browser.ts
@ multi ./src/main.browser.ts webpack-hot-middleware/client?path=/__webpa
ck_hmr&timeout=2000&reload=true&noInfo=true
我正在使用 webpack 2 和 ngtools/webpack 来编译我的项目
使用 JIT 从 node_modules 延迟加载模块工作正常,但使用 AOT 延迟加载无效
github.com/angular/angular-cli/issues/5986
我找到的最佳解决方案是创建一个从 src/app/something 到 node_modules/something
的符号链接ln -s source destination
它运行良好:)