-
-
Notifications
You must be signed in to change notification settings - Fork 97
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Google Closure minifier with Terser #90
Conversation
Thanks for doing the research and making a PR for this! 🙏 A couple of thoughts:
See this note from this page: https://guide.elm-lang.org/optimization/asset_size.html
|
No. I tested it running in two passes and it produces the same output as with one pass.
I guess in general, yes. However, even without the Elm-specific config, it does a good job, so we could run it with the default config until we find a way to differentiate:
|
I did some digging, and was just about to give up, but I finally found this option! Looks like it's quite easy to only apply the plugin to files based on file extension: module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
}),
],
},
}; https://github.com/webpack-contrib/terser-webpack-plugin#test I know that for many cases, applying these optimizations won't cause problems for their JS code. But since it's a framework that supports many different use cases, I want to be conservative about ensuring correctness here. Are you up for trying this Something like this: module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.elm$/i,
}),
new TerserPlugin({
test: /(?!\.elm$)/i,
}),
],
},
}; Note: I didn't test that regex, I just tried this trick for negating: https://stackoverflow.com/questions/1538512/how-can-i-invert-a-regular-expression-in-javascript. But the really important thing is testing if we can only run those Elm-specific options on Elm files, so let's see how that experiment goes first. Let me know what you think! I'm happy to help as well. Feel free to ping me on Slack to coordinate. Parallel flagAlso, I'm up for merging and releasing this once we get the correctness piece. But for performance, it seems like we could use the |
For the time being, we cannot guarantee that the file to be compressed is generated by Elm. Therefore we cannot apply its special optimizations.
I've run into issues with the approach you suggested: Webpack does not look at the original file name, but considers the generated JavaScript file. I.e., the I think at the point where the For the time being, I've disabled those Elm-specific optimizations such that there are no problems with other |
Hi @y0hy0h, thanks so much for your patience on this! Since I think it's reasonable to assume that the setup (including the Elm optimizations) is safe. The functions to optimize:
Is safe because those are all functions that Elm controls and can safely mark as pure. I'll merge this in for this release. I would love to hear how it goes for you with your Windows set up! It would be great if it got Thanks again for the PR! |
@dillonkearns The freshly cloned Unfortunately my own project doesn't compile due to |
Thank you for the update @y0hy0h! Did you update both the NPM and Elm package for your own project? |
@dillonkearns Haha, yes that was it actually! 🤦 Now I'll have to migrate to the new version, as I used |
Oh good, glad it was an easy fix! Yeah, the |
Yeah, already fixed. :) (I've decided to spend some time on this project after all... :D) elm-pages was already very pleasant, and it just keeps getting nicer and nicer! |
Fixes #83. Replaces problematic Google Closure Compiler with terser.
We cannot use uglifyjs, because the
main.js
contains modern JavaScript (const
) whereas uglifyjs can only deal with ES5.uglify-es
is abandoned, but terser is a really nice replacement.