简体   繁体   English

将Angular模块分离到不同的包中

[英]Separate Angular modules to different bundles

In my case I need separate main bundle. 就我而言,我需要单独的主捆绑包。

I need each module to build into its own bundle. 我需要将每个模块构建到自己的捆绑包中。 I have a very large application, with a lot of code. 我有一个非常大的应用程序,其中包含很多代码。 I do not want, that at the slightest change, patch or hotfix users pumped the entire application again. 我不希望补丁或修补程序用户至少稍作改动即可再次泵入整个应用程序。 This is the first long, in the second creates a load on the server. 这是第一个较长的时间,第二个在服务器上创建负载。 I use the serviceworker in my application and all its resources are cached on the client side. 我在应用程序中使用serviceworker,其所有资源都缓存在客户端。

I need to be able to transfer only the popup.bundle.js file when changes are made to pop-ups module. 更改弹出窗口模块时,我仅需要能够传输popup.bundle.js文件。 And with changes in the controls module, only the controls.bundle.js file were transferred. 并且随着控件模块的更改,只传输了controls.bundle.js文件。 I do not need a lazy load. 我不需要延迟加载。 I just need to make sure that each module is going to its bundle and that's it. 我只需要确保每个模块都将绑定到它的捆绑包即可。

If you haven't done it already, group the components you want to bundle in discrete modules, say popup.module and controls.module. 如果尚未完成操作,则将要捆绑的组件组合到离散模块中,例如popup.module和controls.module。 Once you have them, tell webpack that you want them bundled individually: 拥有它们后,告诉webpack您希望它们单独捆绑在一起:

// in angular.json, under projects/{your project}/architect/build/options, add
"lazyModules": ["src/app/popup/popup.module", "src/app/controls/controls.module"]

You could also couple that technique with Angular Elements for event greater separation. 您也可以将该技术与Angular Elements结合使用,以实现更大的事件分离。

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

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