Skip to content

Instantly share code, notes, and snippets.

@nojvek
Created January 15, 2020 19:21
Show Gist options
  • Save nojvek/0c17b0c27d7c43ec9129e6b7c80a8125 to your computer and use it in GitHub Desktop.
Save nojvek/0c17b0c27d7c43ec9129e6b7c80a8125 to your computer and use it in GitHub Desktop.
webpack remove unused code options
const optimizationOptions = {
mode: PRODUCTION ? `production` : `development`,
module: {rules},
optimization: {
chunkIds: `named`,
moduleIds: PRODUCTION ? `hashed` : `named`,
usedExports: true,
minimize: PRODUCTION,
minimizer: [
new TerserPlugin({
extractComments: false,
parallel: true,
terserOptions: {
// see options descriptions at https://github.com/terser/terser#compress-options
// full options list https://github.com/terser/terser/blob/master/lib/compress/index.js
compress: {
defaults: false, // explicitly enabling safe compress options
unused: true, // drop unreferenced functions, variables and exports marked by webpack
dead_code: true, // remove unreachable code
properties: true, // foo["bar"] -> foo.bar
computed_props: true, // {["computed"]: 1} -> {computed: 1}
evaluate: true, // evaluate constant expressions 1 + 1 => 2
},
mangle: {
keep_classnames: true, // preserve classnames to ensure this.constructor.name references work as expected, used in NamedError class
},
output: {
comments: false,
semicolons: false, // use newlines when possible, so devtools don't hang
},
},
}),
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment