-
Notifications
You must be signed in to change notification settings - Fork 825
build: use Terser for production minification #3153
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
base: main
Are you sure you want to change the base?
Conversation
- Add terser devDependency and set build.minify to "terser" in production - Enable source maps only for non-production builds - Disable minification for dev builds - Terser options: mangle names, strip comments, 2 compress passes
WalkthroughAdds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@vite.config.ts`:
- Around line 100-109: The terser config currently sets
terserOptions.format.comments = false which strips all comments (including
required license headers); update the vite minify/terser options so license
comments are preserved by changing terserOptions.format.comments to "some" or a
regex that matches license banners, or alternatively add a Rollup plugin (e.g.,
a license extraction plugin) to collect and emit third‑party licenses into a
LICENSE file while keeping terserOptions.format.comments set to allow banner
preservation; locate the minify block/terserOptions in vite.config.ts (the
isProduction conditional) and adjust format.comments or add the license
extraction plugin accordingly.
🧹 Nitpick comments (1)
vite.config.ts (1)
101-109: Small note:mangle: trueis already the terser default.Not a problem — being explicit is fine for readability. Just mentioning it so you know it can be removed if you prefer less config noise.
| minify: isProduction ? "terser" : false, | ||
| ...(isProduction && { | ||
| terserOptions: { | ||
| compress: { passes: 2 }, | ||
| mangle: true, | ||
| format: { | ||
| comments: false, | ||
| }, | ||
| }, | ||
| }), |
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.
Risk: comments: false strips license comments from bundled libraries.
Setting format.comments: false removes all comments, including license and legal notices from third-party packages (pixi.js, howler, zod, protobufjs, etc.). Many open-source licenses (MIT, Apache-2.0, BSD) require attribution to be preserved in distributed code. Stripping them may violate license terms.
Use comments: "some" or a regex to keep license banners, or pair this with a plugin like rollup-plugin-license to extract them into a separate LICENSE file in the output.
Suggested fix — keep license comments
terserOptions: {
compress: { passes: 2 },
mangle: true,
format: {
- comments: false,
+ comments: /^\/*!/, // keep comments starting with /*! (license banners)
},
},Or extract all licenses into a separate file using a Rollup plugin, which keeps the bundle clean and stays compliant.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| minify: isProduction ? "terser" : false, | |
| ...(isProduction && { | |
| terserOptions: { | |
| compress: { passes: 2 }, | |
| mangle: true, | |
| format: { | |
| comments: false, | |
| }, | |
| }, | |
| }), | |
| minify: isProduction ? "terser" : false, | |
| ...(isProduction && { | |
| terserOptions: { | |
| compress: { passes: 2 }, | |
| mangle: true, | |
| format: { | |
| comments: /^\/*!/, // keep comments starting with /*! (license banners) | |
| }, | |
| }, | |
| }), |
🤖 Prompt for AI Agents
In `@vite.config.ts` around lines 100 - 109, The terser config currently sets
terserOptions.format.comments = false which strips all comments (including
required license headers); update the vite minify/terser options so license
comments are preserved by changing terserOptions.format.comments to "some" or a
regex that matches license banners, or alternatively add a Rollup plugin (e.g.,
a license extraction plugin) to collect and emit third‑party licenses into a
LICENSE file while keeping terserOptions.format.comments set to allow banner
preservation; locate the minify block/terserOptions in vite.config.ts (the
isProduction conditional) and adjust format.comments or add the license
extraction plugin accordingly.
- Update Terser options to enable top-level mangling and increase compression passes from 2 to 3. - Improve minification by dropping unused top-level variables and functions.
Description:
Switch Vite's production minification from esbuild to Terser to improve shipped
bundle minification.
Changes:
build.minify: "terser"+ Terser options (mangle, strip comments,compress.passes: 2)terserdevDependencyPlease complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
DISCORD_USERNAME