terser-loader
Terser loader for webpack
Getting Started
To begin, you'll need to install terser-loader
:
yarn add --dev terser-loader
npm install terser-loader --save-dev
Then add the loader to your webpack
config. For example:
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /.js$/,
use: ['file-loader', 'terser-loader'],
},
],
},
};
Another example:
module.exports = {
module: {
rules: [
{
test: /.js$/,
use: [
{
loader: 'file-loader',
},
{
loader: 'terser-loader',
options: {
stripTrailingSemicolon: true,
terserOptions: {
minify: {
mangle: false,
},
output: {
inline_script: true,
},
},
},
},
],
},
],
},
};
Options
terserOptions
Optional, type: object
, default: {}
See Terser API Reference for details. terserOptions
as passed to Terser API as is.
stripTrailingSemicolon
Optional, type: boolean
, default: false
By default, terser'ed output ends with ;
. It's generally a good idea if you plan on concatenating produced scripts into a bundle at a later stage. Otherwise, you can safely remove ;
by setting stripTrailingSemicolon
to true
and save yet another byte.
License
MIT