It takes forever in "92% chunk asset optimization" can it be cached or disabled?
Bug Report or Feature Request (mark with an x)
- [x] feature request
Versions.
@angular/cli: 1.0.0-rc.2 node: 6.9.2 os: darwin x64 @angular/common: 2.4.10 @angular/compiler: 2.4.10 @angular/core: 2.4.10 @angular/forms: 2.4.10 @angular/http: 2.4.10 @angular/platform-browser: 2.4.10 @angular/platform-browser-dynamic: 2.4.10 @angular/router: 3.4.10 @angular/cli: 1.0.0-rc.2 @angular/compiler-cli: 2.4.10
Desired functionality.
assets optimization it rarely changes when you only do coding, and specially for my project it takes 2-5 minutes each time. So it's killing my productivity. With "--verbose" it doesn't show me any specific files which I could remove temporally to speed up the process of compiling...
Hash: 51ba5014dae3bd179ab9
Time: 395021ms
chunk {0} main.bundle.js, main.bundle.js.map (main) 10.8 MB {4} [initial] [rendered]
chunk {1} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 278 kB {5} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 751 kB {5} [initial] [rendered]
chunk {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 362 kB {5} [initial] [rendered]
chunk {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.44 MB [initial] [rendered]
chunk {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
Thanks.
it took me 1 hr to make a prod build we are using angular 4.4.6 & my build command is node --max_old_space_size=6048 node_modules/@angular/cli/bin/ng build --prod --aot --env=azureDev --extract-css --preserve-symlinks --named-chunks

Wish there was an acknowledgement from the Angular team about this issue and a tentative eta for solution
Same here, Getting stuck at 92% chunk asset optimization UglifyJSPlugin for at least 3 min
@meghma, this item is marked as closed. Maybe open a new issue?
@filipesilva Can you help us with this?
Had the same issue and found some details on font awesome website:
https://fontawesome.com/how-to-use/with-the-api/other/tree-shaking
The workaround I have currently used is to create a patch.js file with the following content:
const fs = require('fs');
const common = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js';
fs.readFile(common, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/compress: {/g, 'compress: { collapse_vars: false,');
fs.writeFile(common, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
And reference it in the package.json
...
"scripts": {
"postinstall": "node patch.js",
...
you'll have to run node/yarn install so it is triggered.
HTH
@lucboutier Doesn't work in my case.
@lucboutier no luck here either, the only thing working for now is disabling compression all together, which is not an option in my case
There's a workaround available for yarn builds, using an alias to replace uglify-es with terser, which includes the root cause fix for the collpase_vars issue. That might be an option for some folks here until that fix makes its way into the Webpack 4 dependencies.
Has anyone tried that for an angular-cli project?
(UPDATE Sept 26, 2018: this change will not make it into Webpack 4 deps, but the Webpack 5 roadmap includes a move to terser which has the fix.)
Managed to get it working by explicitly overriding all compress settings with their default values according to the docs (I have yet to figure out why that actually works though).
An update for the script from @lucboutier :
const fs = require('fs');
const common = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js';
fs.readFile(common, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/compress: {[^}]*}/g, 'compress: {\n' +
' arrows: true,\n' +
' booleans: true,\n' +
' collapse_vars: true,\n' +
' comparisons: true,\n' +
' computed_props: true,\n' +
' conditionals: true,\n' +
' dead_code: true,\n' +
' drop_console: false,\n' +
' drop_debugger: true,\n' +
' ecma: wco.supportES2015 ? 6 : 5,\n' +
' evaluate: true,\n' +
' expression: false,\n' +
' global_defs: {},\n' +
' hoist_funs: false,\n' +
' hoist_props: true,\n' +
' hoist_vars: false,\n' +
' if_return: true,\n' +
' // Workaround known uglify-es issue\n' +
' // See https://github.com/mishoo/UglifyJS2/issues/2949#issuecomment-368070307\n' +
' inline: wco.supportES2015 ? 1 : 3,\n' +
' join_vars: true,\n' +
' keep_classnames: false,\n' +
' keep_fargs: true,\n' +
' keep_fnames: false,\n' +
' keep_infinity: false,\n' +
' loops: true,\n' +
' negate_iife: true,\n' +
' // PURE comments work best with 3 passes.\n' +
' // See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.\n' +
' passes: buildOptions.buildOptimizer ? 3 : 1,\n' +
' properties: true,\n' +
' pure_funcs: null,\n' +
' pure_getters: buildOptions.buildOptimizer,\n' +
' reduce_funcs: true,\n' +
' reduce_vars: true,\n' +
' sequences: true,\n' +
' side_effects: true,\n' +
' switches: true,\n' +
' toplevel: false,\n' +
' top_retain: null,\n' +
' typeofs: true,\n' +
' unsafe: false,\n' +
' unsafe_arrows: false,\n' +
' unsafe_comps: false,\n' +
' unsafe_Function: false,\n' +
' unsafe_math: false,\n' +
' unsafe_methods: false,\n' +
' unsafe_proto: false,\n' +
' unsafe_regexp: false,\n' +
' unsafe_undefined: false,\n' +
' unused: true,\n' +
' warnings: false\n' +
' }');
fs.writeFile(common, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
To prevent the memory issue ng build still has to be run in a context with increased memory available
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build ...
Hope still helps someone.
Currently experiencing this issue.
Angular CLI: 6.1.3
Node: 8.11.3
OS: win32 x64
Angular: 6.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.7.3
@angular-devkit/build-angular 0.7.3
@angular-devkit/build-optimizer 0.7.3
@angular-devkit/build-webpack 0.7.3
@angular-devkit/core 0.7.3
@angular-devkit/schematics 0.7.3
@angular/cli 6.1.3
@ngtools/webpack 6.1.3
@schematics/angular 0.7.3
@schematics/update 0.7.3
rxjs 6.2.2
typescript 2.7.2
webpack 4.9.2
@egervari 's solution of:
"build-prod": "node --max-old-space-size=8192 node_modules/@angular/cli/bin/ng build --prod --aot",
Makes the build go from ~12 minutes to 2 seconds for me.
@mlwilkerson: Worked with angular-cli. Thanks for the hint :+1:
@mlwilkerson: terser is working great - Significantly reduced build times from > 50 minutes to < 2 minutes for me.
Here's what I did (more of a temporary solution):
# Add terser to dependencies
npm install terser --save-dev
# Remove uglify-js
rm -r node_modules/uglify-js
rm -r node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es
# Symlink to terser (which is fully compatible)
ln -s $(pwd)/node_modules/terser $(pwd)/node_modules/uglify-js
ln -s $(pwd)/node_modules/terser $(pwd)/node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es
@konstantinkoeppe thanks for the script. building time decreased by 30%
konstantinkoeppe is the only solution I found in this thread. Great job mate.
Trying to build this in a docker container. Had no luck with any of the above approaches. Always hangs at 92%.
Why did this issue get closed?
FYI: I'm using the linux shell on windows. When I use the linux shell it's terribly slow (didn't even wait to finish).
When I use powershell it builds in 10seconds.
https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/272
I found this solution node --max_old_space_size=4096 node_modules/.bin/webpack -p --progress --profile Hopefully, this will help someone.
@anupy Any tips on what we do with that line and how it will help? I don't see the connection, yet.
I had also a very slow build time from up to 20 min. But in my case, i had to optimize the imports. So, the tree shaking will not have to many to do. Especially the optimization of the fontawesome imports to deep imports solved the build time problem. Maybe this will help someone.
I can confirm moving to terser has done the trick as described by @mlwilkerson , the short simple steps are:
npm i terser --save-dev
and then
"resolutions": {
"uglify-es": "npm:terser"
}
In your package.json
My build reduced to less than a minute. (from over several mins)