首页 文章

从node_modules加载Angular Lazy

提问于
浏览
2

我在多个Git Repos之间拆分我的项目,现在我遇到了Lazy加载的问题

如果我使用以下语法将sourceCode从子仓库复制到主仓库

{
    path: 'child-app',
    loadChildren: './shared/child/src/app/child-app.module#ChildAppModule'
},

我可以毫无问题地构建和服务我的项目但是如果我将Route更改为指向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来编译我的项目

1 回答

  • 1

    来自带有JIT的node_modules的延迟加载模块工作正常但是使用AOT的延迟加载不起作用

    github.com/angular/angular-cli/issues/5986

    我找到的最佳解决方案是创建一个从src / app / something到node_modules / something的符号链接

    ln -s source destination
    

    它工作得很好:)

相关问题