Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Apply Uglify multiple times to the same code #364

Closed
joecorkerton opened this issue Oct 11, 2018 · 6 comments
Closed

Apply Uglify multiple times to the same code #364

joecorkerton opened this issue Oct 11, 2018 · 6 comments

Comments

@joecorkerton
Copy link

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.

@alexander-akait
Copy link
Member

@joecorkerton create two instance of plugin and put second instance after first

@joecorkerton
Copy link
Author

joecorkerton commented Oct 11, 2018

@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?

@alexander-akait
Copy link
Member

@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

@joecorkerton
Copy link
Author

joecorkerton commented Oct 11, 2018

@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

@alexander-akait
Copy link
Member

@joecorkerton please create minimum reproducible test repo and describe what you have and what you expected, i can't understand you

@kzc
Copy link

kzc commented Oct 18, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants