Skip to content

Commit

Permalink
feat: added SWC HTML minifier
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 9, 2022
1 parent 84f54bd commit 3b7ea1d
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 3 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

# html-minimizer-webpack-plugin

This plugin uses [html-minifier-terser](https://github.com/terser/html-minifier-terser) to optimize and minify your HTML.
This plugin can use 2 tools to optimize and minify your HTML:

- [`html-minifier-terser`](https://github.com/imagemin/imagemin) (by default) - JavaScript-based HTML minifier.
- [`swc`](https://github.com/swc-project/swc) - very fast Rust-based platform for the Web.

## Getting Started

Expand All @@ -35,6 +38,24 @@ or
pnpm add -D html-minimizer-webpack-plugin
```

**Additional step**: If you want to use `@swc/html` you need to install it:

```console
npm install @swc/html --save-dev
```

or

```console
yarn add -D @swc/html
```

or

```console
pnpm add -D @swc/html
```

Then add the plugin to your `webpack` configuration. For example:

**webpack.config.js**
Expand Down Expand Up @@ -67,7 +88,17 @@ module.exports = {
minimizer: [
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
// `...`

// For `html-minifier-terser`:
//
new HtmlMinimizerPlugin(),

// For `@swc/html`:
//
// new HtmlMinimizerPlugin({
// minify: HtmlMinimizerPlugin.swcMinify,
// minimizerOptions: {}
// })
],
},
};
Expand Down Expand Up @@ -253,6 +284,12 @@ Default: `HtmlMinimizerPlugin.htmlMinifierTerser`

Allows you to override default minify function.
By default, plugin uses [html-minifier-terser](https://github.com/terser/html-minifier-terser) package.

We currently support:

- `HtmlMinimizerPlugin.htmlMinifierTerser`
- `HtmlMinimizerPlugin.swcMinify`

Useful for using and testing unpublished versions or forks.

> **Warning**
Expand Down
Loading

0 comments on commit 3b7ea1d

Please sign in to comment.