Ask questionsadd option to disable concatenateModules when build
my project build is too slow (in my computer it may 300 - 400s, but in bit bucket pipeline it may took 15 minute), so i try to find way to speed up.
i found that most of time use in ModuleConcatenationPlugin. so i just curious if i disable ModuleConcatenationPlugin can improve build speed up. so i edit
node_modules\@angular-devkit\build-angular\src\angular-cli-files\models\webpack-configs\common.js and add
concatenateModules: false, to
this is my test result when build 3 times. it improve speed around 30-50%. and it has same number of chunk (at least total *.js is equals
|ModuleConcatenationPlugin||total *.js||time 1||time 2||time 3||Avg (ms)|
and this is when i build on Google Cloud Build (because it slower than my PC) .as you can see it reduce time from 13 min to around 7 min.
|ModuleConcatenationPlugin||time 1||time 2||time 3||Avg (ms)|
downside of disable ModuleConcatenationPlugin it may increase bundle size. this is my project size. (from du -bcs )
i am not sure but i think angular should not need ModuleConcatenationPlugin since angular handle chunk by lazy route module. i am not sure angular can get benefit from ModuleConcatenationPlugin? or may be i just misunderstand something?
it would be nice if add option to disable concatenateModules in angular.json or build command
just run this command before build to disable concatenateModules
sed -i "s/noEmitOnErrors: true,$/noEmitOnErrors: true,concatenateModules: false,/" "node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js"
Answer questions alan-agius4
concatenateModules is used for scope hoisting, which results in 2 things, smaller bundle sizes and faster code execution in the browser.
If really want to disable
concatenateModules which is not recommended you can use ngx-build-plus.
From a CLI point of view, exposing a way to disable
concatenateModules is out of scope, because we wouldn't like users to opt-out from key runtime performance and bundle size optimisations.
You can read more about this here: https://webpack.js.org/plugins/module-concatenation-plugin