terser-loader

2.0.3 • Public • Published

npm node deps size

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.

License

MIT

Package Sidebar

Install

npm i terser-loader

Weekly Downloads

1,421

Version

2.0.3

License

MIT

Unpacked Size

5.7 kB

Total Files

6

Last publish

Collaborators

  • 5lava