简体   繁体   English

如何在没有CLI的情况下延迟加载Angular模块?

[英]How to lazy load Angular module without CLI?

I have yet to find this specific use case described any where. 我还没有找到任何描述的具体用例。 If it exists, please refer me to it. 如果存在,请转介我。

I would like to achieve lazy loading of Angular modules (using Angular version 7), because we use many large 3rd party libraries for specific parts of our app that are rarely used. 我想实现延迟加载Angular模块(使用Angular版本7),因为我们使用很多大型第三方库来处理很少使用的应用程序的特定部分。 However, we do not use the Angular CLI (ng command). 但是,我们不使用Angular CLI(ng命令)。 All examples I have seen use Angular CLI to build the module chunk, and load via a path string, either in loadChildren or some other way. 我见过的所有示例都使用Angular CLI构建模块块,并通过路径字符串加载,可以是loadChildren ,也可以是其他方式。

Our build is managed with Webpack (webpack.config.js file). 我们的构建使用Webpack(webpack.config.js文件)进行管理。 My understanding is that Angular CLI is a build tool, and use of Angular does not require it. 我的理解是Angular CLI是一个构建工具,使用Angular并不需要它。 Since we know this functionality exists in Angular, there must be a way to leverage it without the CLI. 由于我们知道Angular中存在此功能,因此必须有一种方法可以在没有CLI的情况下利用它。 I don't mind hacky solutions to this, as it is my hope that this feature may be more robustly introduced in the future to the Angular framework. 我不介意hacky这个解决方案,因为我希望将来可以更有力地将此功能引入Angular框架。

Any crumb of information will be appreciated. 任何一些信息都将受到赞赏。

All examples I have seen use Angular CLI to build the module chunk, and load via a path string, either in loadChildren or some other way. 我见过的所有示例都使用Angular CLI构建模块块,并通过路径字符串加载,可以是loadChildren,也可以是其他方式。

That's right, but if you don't use Angular CLI, the next thing you have to do is to install angular-router-loader package and afterwards in your webpack.config.js file you add it to to your typescript loaders: 这是对的,但是如果你不使用Angular CLI,接下来要做的就是安装angular-router-loader软件包,然后在webpack.config.js file中将它添加到你的打字机加载器:

loaders: [
  {
    test: /\.ts$/,
    loaders: [
      'awesome-typescript-loader'
    ]
  },
  {
    test: /\.(ts|js)$/,
    loaders: [
      'angular-router-loader'
    ]
  }  
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM