Skip to content

Instantly share code, notes, and snippets.

@ryankshaw
Created September 30, 2024 18:07
optimal minification setttings to get best tradeoff between file size, speed, and debuggability
module.exports = {
// ...
optimization: {
minimizer: [
new SwcJsMinimizerRspackPlugin({
compress: {
// prevents it from combining a bunch of statements with ","s so it is easier to set breakpoints
sequences: false,
// these are all things that terser does by default but we turn
// them off because they don't reduce file size enough to justify the
// time they take, especially after gzip:
// see: https://slack.engineering/keep-webpack-fast-a-field-guide-for-better-build-performance-f56a5995e8f1
booleans: false,
collapse_vars: false,
comparisons: false,
computed_props: false,
hoist_props: false,
if_return: false,
join_vars: false,
keep_infinity: true,
loops: false,
negate_iife: false,
properties: false,
reduce_funcs: false,
reduce_vars: false,
typeofs: false,
},
output: {
// this is where the vast majority of the benefits from minification come from:
// just removing all the comments
comments: false,
// prevents everything being on one line so it's easier to view in devtools
semicolons: false,
},
}),
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment