首页 > 解决方案 > Is there a way to create a separate bundle file for dependencies in package.json using angular-cli?

问题描述

I have multiple angular applications that I load in multiple pages. I am trying to minimize bundle download size when I am loading a particular application. I cannot use lazy loading here as I am using multiple angular application, but all of these applications have same dependencies.

When I try ng build --prod , it includes the dependency code within main.js bundle, which I don't want. I want to get dependency code bundle separately so that I don't download redundant code when I am navigating through pages.

标签: angularangular-cli

解决方案


是的,

--vendor-chunk=true

或者在配置选项下的 angular.json 中:

"vendorChunk": true,

来自 build 命令的 angular-cli 文档:

When using Build Optimizer the vendor chunk will be disabled by default. You can override this with --vendor-chunk=true.

https://github.com/angular/angular-cli/wiki/build#--build-optimizer-and---vendor-chunk


推荐阅读