|
13 | 13 |
|
14 | 14 | # terser-webpack-plugin |
15 | 15 |
|
16 | | -This plugin uses [terser](https://github.com/terser/terser) to minify/minimize your JavaScript by default, and can also minify other asset types — JSON and HTML — via built-in minimizers. |
| 16 | +This plugin minifies your assets in a webpack build. It ships with several |
| 17 | +built-in minimizers covering JavaScript, JSON, and HTML — pick one with the |
| 18 | +[`minify`](#minify) option and target the right files with [`test`](#test). |
17 | 19 |
|
18 | | -For HTML it can use 3 tools: |
| 20 | +JavaScript minimizers: |
19 | 21 |
|
20 | | -- [`html-minifier-terser`](https://github.com/terser/html-minifier-terser) — JavaScript-based HTML minifier (the default for HTML). |
21 | | -- [`@swc/html`](https://github.com/swc-project/swc) — very fast Rust-based platform for the Web. |
22 | | -- [`@minify-html/node`](https://github.com/wilsonzlin/minify-html) — a Rust HTML minifier, optimised for speed. |
| 22 | +- [`terser`](https://github.com/terser/terser) — `TerserPlugin.terserMinify` (default). The same JavaScript-based minifier that webpack uses out of the box; produces small, well-tested output and supports the full set of `extractComments` modes. |
| 23 | +- [`uglify-js`](https://github.com/mishoo/UglifyJS) — `TerserPlugin.uglifyJsMinify`. ES5-only minifier, useful when you specifically need UglifyJS-compatible output. Requires `npm install --save-dev uglify-js`. |
| 24 | +- [`@swc/core`](https://github.com/swc-project/swc) — `TerserPlugin.swcMinify`. A very fast Rust-based JavaScript/TypeScript minifier. Requires `npm install --save-dev @swc/core`. |
| 25 | +- [`esbuild`](https://github.com/evanw/esbuild) — `TerserPlugin.esbuildMinify`. An extremely fast JS bundler/minifier; legal comments are always preserved (no `extractComments` support). Requires `npm install --save-dev esbuild`. |
| 26 | + |
| 27 | +JSON minimizer: |
| 28 | + |
| 29 | +- `JSON.stringify` — `TerserPlugin.jsonMinify`. Built in (no extra dependency); supports `space` and `replacer` options. |
| 30 | + |
| 31 | +HTML minimizers: |
| 32 | + |
| 33 | +- [`html-minifier-terser`](https://github.com/terser/html-minifier-terser) — `TerserPlugin.htmlMinifierTerser`. The default HTML minimizer. JavaScript-based, no native dependency. Requires `npm install --save-dev html-minifier-terser`. |
| 34 | +- [`@swc/html`](https://github.com/swc-project/swc) — `TerserPlugin.swcMinifyHtml` (full HTML documents) and `TerserPlugin.swcMinifyHtmlFragment` (HTML fragments, e.g. `<template>` content). Very fast Rust-based platform for the Web. Requires `npm install --save-dev @swc/html`. |
| 35 | +- [`@minify-html/node`](https://github.com/wilsonzlin/minify-html) — `TerserPlugin.minifyHtmlNode`. A Rust HTML minifier optimised for speed and effectiveness. Requires `npm install --save-dev @minify-html/node`. |
| 36 | + |
| 37 | +All of the non-default minimizers are declared as **optional** peer |
| 38 | +dependencies — install only the ones you actually use. You can also stack |
| 39 | +multiple `TerserPlugin` instances in the same build to handle different |
| 40 | +file types with different minimizers (see [Examples](#examples)). |
23 | 41 |
|
24 | 42 | ## Getting Started |
25 | 43 |
|
|
0 commit comments