-
Notifications
You must be signed in to change notification settings - Fork 396
FullLink Scala.js-specific minifier #4482
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
Comments
Explanation of how mangling works: in terser: https://terser.org/docs/cli-usage#cli-mangling-property-names-mangle-props |
so I actually did get some property mangling to work with terser. I don't know how safe it is so I have it disabled for now but I basically fed it some regexes of package names in our project together with these important options.
I used the following snippet, the reserved words I pulled from the ClosureLinkerBackend. I included some examples of packages this project uses. Anyways, not sure where to go with this outside of telling you I think it's possible with no work on the scalajs side, which is exciting.
|
I tried this and got a nice size reduction. However (I think this is expected) it doesn't work with dynamic loading. I think it won't know what names to call on the other js files if they are mangled independently |
@cquiroz if you are talking about |
It works but not ideal, still need a solution for mangle properties |
I've had a look at the terser options, and it seems we should be able to make it work with Scala.js: Doc: https://terser.org/docs/api-reference#mangle-properties-options
Unclear to me is how to best integrate. To integrate it externally (based on the linking report only), we need to expose quite a bit of the guts of the linker:
On the flipside, we wouldn't have to do anything for sourcemaps. |
Actually, multiple modules may also work with Closure Compiler, there is
and Scala.js has knowledge about inter-module dependencies, right? |
That's not the problem. We've known about that for a while. The problem is mainly that GCC refuses to consider and preserve |
Is this one of the issues? google/closure-compiler#3707 |
All the details are already in #3893. |
@sjrd I was thinking of this limitation even when module kind is CommonJS: require(moduleSet.modules.size <= 1,
"Cannot use multiple modules with the Closure Compiler") |
Since modules are now supported and work great with scala.js, but don't work great with the Closure compiler, and apparently won't ever work with it. I think it would be great to have some sort of simple property name minifier. Current, good javascript minifiers do well with ES imports and are able to tree shake most of the unused stuff. They do well with class name minification as well. However, where they fail is property minification.
In scala.js we have access to a lot more semantic information so it might not be too tough to create a simple minification of property names, I think it would drastically reduce the output javascript size. Today the code is pretty compressable but it could be a lot better.
Another option could be some guidance on how to pass the right parameters to something like Terser if there were some conventions that were universally applicable. https://terser.org/docs/api-reference.html#mangle-properties-options
The text was updated successfully, but these errors were encountered: