The terser-webpack-plugin is a JavaScript minimization plugin for webpack. It utilizes terser to minimize your JavaScript code.
To use terser-webpack-plugin, you first need to install it using npm, yarn, or pnpm like this:
npm install terser-webpack-plugin --save-dev
yarn add -D terser-webpack-plugin
pnpm add -D terser-webpack-plugin
Then, include the terser-webpack-plugin in your webpack
config like this:
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
};
Finally, run webpack
using the method you prefer. The plugin also supports various configurations such as test
, include
, exclude
, parallel
, minify
, terserOptions
, and extractComments
.
The terser-webpack-plugin documentation is available on GitHub. The documentation provides a detailed explanation of the plugin's installation process, usage, options, and examples. It also furnishes guidelines on how to contribute to the project.