-
Notifications
You must be signed in to change notification settings - Fork 4.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
Switch from UglifyJS to Terser to build the polyfill script #65278
Conversation
Size Change: -29 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in c8e19cd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10829344381
|
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.
Looks good ✅
Fixed core-js comment is there as expected:
Any default terser settings differ from the uglifyjs ones? Maybe it's worth checking.
I'm not sure if and how this script is ran during Gutenberg build. Maybe only Core builds the polyfill?
Yes it is. It's part of wp-scripts build
/ wp-scripts start
. See:
presets: [ '@wordpress/babel-preset-default' ], |
and:
), |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@tyxla what you're linking to are usages of the Babel preset. I.e., the |
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.
LGTM, the file built correctly, and the file size is similar 👍
This also prepares us for a feature where polyfill code is not written in ES5.
Great work, @jsnajdr! 🙌
Hmm yes, you're right. I don't see an immediate direct usage of the script itself. Maybe the script was there solely to quickly test the package functionality, like we did for this PR. |
I finally found how it's used:
|
Webpack and other tools switched from UglifyJS to Terser several years ago, but our script for bundling the
polyfill
script still uses UglifyJS. This PR switches to latest version of Terser.Terser-minified files are around 1% bigger that uglified ones. I've seen this elsewhere, too. But I guess it's worth using the same minifier consistently.
I fixed the condition that preserves license comments to also catch a lowercase
"license"
string. Then the minifiedpolyfill.min.js
has a license comment at the beginning.How to test:
cd packages/babel-preset-default
and runnpm run build
. The build files are in the package's./build
subfolder.I'm not sure if and how this script is ran during Gutenberg build. Maybe only Core builds the polyfill?