Apply Uglify multiple times to the same code
joecorkerton opened this issue · 6 comments
Is it possible to apply uglify twice to the same code? I need to do the webpack equivalent of
uglifyjs elm.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters=true,keep_fargs=false,unsafe_comps=true,unsafe=true,passes=2' --output=elm.js && uglifyjs elm.js --mangle --output=elm.js
Why?
It's necessary to run Uglify twice if you use the pure_funcs flag, because if you enable both --compress and --mangle at the same time, the pure_funcs argument will have no effect; Uglify will mangle the names first and then not recognize them when it encounters those functions later.
@joecorkerton create two instance of plugin and put second instance after first
@evilebottnawi and if I include:
with the same string it will figure out to apply the second uglify to the already transformed code? Intuitively it seems like that it would not figure that out
Otherwise what should I do instead of the second include
?
@joecorkerton just use:
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
//...
optimization: {
minimizer: [new UglifyJsPlugin(), new UglifyJsPlugin()]
}
};
You can define own options, also you can exclude/include chunks what should be do not uglify twice
@evilebottnawi Thanks for your help so far.
I have been playing around with different config options and it seems like I'm not able to disable mangle now. I set mangle to false and the output is still minified, with the same filesize. This seems to be the same issue as #234 . Is there a solution for that? Reading through the issue didn't help much
@joecorkerton please create minimum reproducible test repo and describe what you have and what you expected, i can't understand you
uglifyjs elm.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters=true,keep_fargs=false,unsafe_comps=true,unsafe=true,passes=2' --output=elm.js && uglifyjs elm.js --mangle --output=elm.js
Elm is doing that to work around a bug in uglify-js
.
See parcel-bundler/parcel#2062 (comment) for the correct way to do it in both Terser and Uglify.
minimizer: [new UglifyJsPlugin(), new UglifyJsPlugin()]
That's inefficient - that would parse and output the code twice.
Instead just set the compress
option passes
to 2 or greater.