Skip to content

Commit 56e885a

Browse files
committed
perf(build): Optimize terser minifier config for CDN bundles
Enable additional terser compress and mangle options that safely reduce the size of CDN bundle .min.js files: - compress.passes: 5 (multi-pass finds more dead code) - compress.ecma: 2020 (allows modern syntax: nullish coalescing, optional chaining) - compress.toplevel: true (better variable inlining within the IIFE) - compress.unsafe_arrows: true (function → arrow where this is unused, ~1.3KB raw) - compress.unsafe_methods: true ({ m: function(){} } → { m(){} }) - compress.unsafe_comps/unsafe_math/pure_getters: safe algebraic opts - mangle.toplevel: true (mangle top-level names inside IIFE scope) Also adds 'sW' to the mangle reserved list (used by a follow-up change that shortens the sentryWrapped function name for frame stripping). These options only affect CDN .min.js bundles, not npm ESM/CJS output. Saves ~300 bytes gzipped on the base browser bundle. Co-Authored-By: Claude claude@anthropic.com
1 parent 9f779f5 commit 56e885a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

dev-packages/rollup-utils/plugins/bundlePlugins.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export function makeTerserPlugin() {
101101
// mangler won't touch user-facing things, but `sentryWrapped` is not user-facing, and would be mangled during
102102
// minification. (We need it in its original form to correctly detect our internal frames for stripping.) All three
103103
// are all listed here just for the clarity's sake, as they are all used in the frames manipulation process.
104-
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
104+
reserved: ['captureException', 'captureMessage', 'sentryWrapped', 'sW'],
105+
toplevel: true,
105106
properties: {
106107
// allow mangling of private field names...
107108
regex: /^_[^_]/,
@@ -141,6 +142,16 @@ export function makeTerserPlugin() {
141142
],
142143
},
143144
},
145+
compress: {
146+
passes: 5,
147+
ecma: 2020,
148+
toplevel: true,
149+
unsafe_comps: true,
150+
unsafe_math: true,
151+
pure_getters: true,
152+
unsafe_arrows: true,
153+
unsafe_methods: true,
154+
},
144155
output: {
145156
comments: false,
146157
},

0 commit comments

Comments
 (0)