Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elm minification is not two-phase #2062

Closed
Janiczek opened this issue Sep 26, 2018 · 2 comments
Closed

Elm minification is not two-phase #2062

Janiczek opened this issue Sep 26, 2018 · 2 comments

Comments

@Janiczek
Copy link

馃悰 bug report

To be most effective, Elm minification with uglifyjs should be done in two phases. It is currently done in one phase.

馃 Expected Behavior

The minification process does something analogous to this:

uglifyjs elm.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' --output=elm.phase1.js
uglifyjs elm.phase1.js --mangle --output=elm.min.js # phase 2

As seen in the official Elm page:

Note 1: uglifyjs is called twice there. First to --compress and second to --mangle. This is necessary! Otherwise uglifyjs will ignore our pure_funcs flag.

馃槸 Current Behavior

Currently the options passed to uglifyjs have both compress and mangle options set, and uglifyjs is only called once, as seen here: https://github.com/parcel-bundler/parcel/blob/master/src/assets/ElmAsset.js#L89-L119

Thus, there are gains to be ... gained! 馃 馃槄

馃拋 Possible Solution

Let's call the uglifyjs twice, with two different options, closely modelling the recommended CLI usage.

@kzc
Copy link

kzc commented Sep 26, 2018

To be most effective, Elm minification with uglifyjs should be done in two phases. It is currently done in one phase.

That's not required in Terser because pure_funcs works correctly with both compress and mangle enabled in the same minify invocation.

pure_funcs in uglify-js can also be made to work correctly with both compress and mangle enabled if the rename pass is disabled via --no-rename.

See:

However, the caveat is that parcel only performs Terser compress per JS asset and does not perform compress on the final bundle. It would produce a smaller bundle if each asset were not minified individually, but instead only invoke minify on the final bundle - as webpack and rollup typically do.

@Janiczek
Copy link
Author

Ah, thanks for clarifying!

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

No branches or pull requests

3 participants