【问题标题】:Angular Lazy loading from node_modules从 node_modules 角度延迟加载
【发布时间】:2017-12-05 20:34:39
【问题描述】:

我在多个 Git 存储库之间拆分了我的项目,现在我遇到了延迟加载问题

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

{
    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 来编译我的项目

【问题讨论】:

标签: angular webpack lazy-loading webpack-2


【解决方案1】:

使用 JIT 从 node_modules 延迟加载模块工作正常,但使用 AOT 延迟加载不起作用

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

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

ln -s source destination

它工作正常:)

【讨论】:

  • 你有没有一个可以工作的原型。一个笨蛋什么的。
  • 不幸的是,我无法创建 plunker,因为它是一个链接,并且 plunker 中没有链接选项。该主题与拆分为多个 git 存储库的 Angular 项目有关。只需将它们添加到您的 npm 并使用该命令创建一个从 src 到 node_modules 的链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多