-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(es/minifier): Implement minifier #1302
Conversation
Are you thinking of implementing it using UglifyJS? |
@soilSpoon Yes, but mainly because I don't know well about internals of minifiers. Or I can add some passes after implementing it using uglifyjs. |
uglifyjs doesn't seem to be able to minify ECMAScript 2015 or above. So, to use this, you need to use it after transpile it to ECMAScript 2015 or lower. I think It seems good to understand minify in the future and implement it yourself. Referenceterser vs uglifyjs |
@soilSpoon Oh. I got it. Thanks! |
You may also want to look at babel-minify for inspiration. From what I recall, it doesn't achieve quite the same size wins as Uglify or Terser. But the port may be significantly more straightforward - the minifier is split into discrete operations for the different types of transformations that it applies. |
5ba891c
to
f12de1e
Compare
/// throw x(); | ||
/// } | ||
/// ``` | ||
pub(super) fn optimize_in_fn_termiation(&mut self, e: &mut Expr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
pub(super) fn optimize_in_fn_termiation(&mut self, e: &mut Expr) { | |
pub(super) fn optimize_in_fn_termination(&mut self, e: &mut Expr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks!
Hey, I maintain Terser, and it's helplessly slow. Recently I started a port to rust (in a very early stage) but I don't think it's useful to keep two separate projects that are essentially the same. How can I help? |
@fabiosantoscode I implemented many rules but there are many rules left. Note that being in-tree would make version management much simpler, as bundler depends on minifier and minifier depends on ast / visitor while those crates live in a momorepo. |
Ok, I'll go on your fork and send PRs when I have the time. I'm interested in how to implement |
Any possible to expose as webpack plugin like terser |
When developing the property mangler, I'd commented out the lines in this 'if' statement so I could run tests faster. So I came up with this PR to enable us to filter tests when desired, and run them quickly, but also allow to run everything by omitting filter arguments. If you have a better idea for testing quickly please let me know :) this is still pretty slow.
👍 That's also my goal. |
However, I see this PR had beed merged, but how can I try it out? At now, it only removes comment and space in my code. |
@SoloJiang It's not published yet because it's not done |
So much excitement for this port, I love it 💖 I need to try to reduce my hours in my side gig so I can give this more attention. There's some transforms Terser itself doesn't do that are feasible here (such as a dictionary for common immutable constants or cross-module intelligence used in combination with spack) that can reduce this port's output bytes to a point that makes it a viable alternative to Terser. |
I'm glad to hear that and thank you!
Sounds interesting. I expect such cross-module transforms to reduce final output by a margin because libraries used a lot along with UI frameworks like react encourages such code. |
Postponed
To simplify management, I'll merge this PR as incomplete state and implement more rules with follow-up PRs.
swc_bundler:
swc_ecma_minifier: