enhance terser options to minify the bundle. I am using javascript classes and bundling…
- User
enhance terser options to minify the bundle. I am using javascript classes and bundling with rollup.
terser({ compress: { passes: 2, pure_getters: true, unsafe_math: true, }, mangle: { properties: { regex: /^_/, }, }, }),
- Assistant
Here are a few additional options you can add to enhance the terser options for even further bundle minification:
-
ecma: Use this option to indicate the ECMAScript version of your code. This can help terser to better understand the syntax of your code and optimize it accordingly. For example, you can setecma: 2018to indicate that you are using ECMAScript 2018 syntax. -
module: Use this option to indicate the module type of your code. For example, you can setmodule: trueto indicate that you are using ES6 modules. -
toplevel: Use this option to enable toplevel variable and function renaming. This can help terser to rename variables and functions across the entire bundle to shorten their names and reduce the bundle size.
Here's an example of how these options can be added to the terser configuration:
terser({ compress: { passes: 2, pure_getters: true, unsafe_math: true, }, mangle: { properties: { regex: /^_/, }, }, ecma: 2018, module: true, toplevel: true, }), -