terser-loader
v2.0.3
Published
Terser loader for webpack
Downloads
27,274
Maintainers
Readme
terser-loader
Terser loader for webpack
Getting Started
To begin, you'll need to install terser-loader
:
- Using yarn:
yarn add --dev terser-loader
- Using npm:
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.