Socket
Socket
Sign inDemoInstall

html-minimizer-webpack-plugin

Package Overview
Dependencies
106
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0 to 4.2.0

4

dist/index.js

@@ -18,4 +18,5 @@ "use strict";

const {
throttleAll,
htmlMinifierTerser,
throttleAll
swcMinify
} = require("./utils");

@@ -478,2 +479,3 @@

HtmlMinimizerPlugin.htmlMinifierTerser = htmlMinifierTerser;
HtmlMinimizerPlugin.swcMinify = swcMinify;
module.exports = HtmlMinimizerPlugin;

@@ -5,2 +5,4 @@ "use strict";

/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/** @typedef {import("./index.js").Input} Input */

@@ -68,3 +70,3 @@

* @param {Input} input
* @param {HtmlMinifierTerserOptions | undefined} [minimizerOptions]
* @param {CustomOptions | undefined} [minimizerOptions]
* @returns {Promise<MinimizedResult>}

@@ -108,6 +110,27 @@ */

}
/**
* @param {Input} input
* @param {CustomOptions | undefined} [minimizerOptions]
* @returns {Promise<MinimizedResult>}
*/
/* istanbul ignore next */
async function swcMinify(input, minimizerOptions = {}) {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved
const swcMinifier = require("@swc/html");
const [[, code]] = Object.entries(input);
const result = await swcMinifier.minify(Buffer.from(code), { ...minimizerOptions
});
return {
code: result
};
}
module.exports = {
throttleAll,
htmlMinifierTerser
htmlMinifierTerser,
swcMinify
};
{
"name": "html-minimizer-webpack-plugin",
"version": "4.1.0",
"version": "4.2.0",
"description": "html minimizer plugin for Webpack",

@@ -47,6 +47,11 @@ "license": "MIT",

},
"peerDependenciesMeta": {
"@swc/html": {
"optional": true
}
},
"dependencies": {
"@types/html-minifier-terser": "^7.0.0",
"html-minifier-terser": "^7.0.0",
"jest-worker": "^27.5.1",
"jest-worker": "^29.0.3",
"schema-utils": "^4.0.0",

@@ -57,9 +62,10 @@ "serialize-javascript": "^6.0.0"

"@babel/cli": "^7.18.9",
"@babel/core": "^7.18.9",
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.9",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@types/serialize-javascript": "^5.0.2",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^28.1.3",
"babel-jest": "^29.0.3",
"@swc/html": "^0.0.15",
"copy-webpack-plugin": "^9.0.1",

@@ -69,7 +75,7 @@ "cross-env": "^7.0.3",

"del-cli": "^4.0.1",
"eslint": "^8.21.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.1",
"jest": "^28.1.3",
"jest": "^29.0.3",
"lint-staged": "^13.0.3",

@@ -76,0 +82,0 @@ "memfs": "^3.4.7",

@@ -16,4 +16,7 @@ <div align="center">

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

@@ -39,2 +42,20 @@

**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:

@@ -72,3 +93,13 @@

// `...`
// For `html-minifier-terser`:
//
new HtmlMinimizerPlugin(),
// For `@swc/html`:
//
// new HtmlMinimizerPlugin({
// minify: HtmlMinimizerPlugin.swcMinify,
// minimizerOptions: {}
// })
],

@@ -84,2 +115,9 @@ },

> **Note**
>
> Removing and collapsing spaces in the tools differ (by default).
>
> - `html-minifier-terser` - always collapse multiple whitespaces to 1 space (never remove it entirely), but you can change it using [`options`](https://github.com/terser/html-minifier-terser#options-quick-reference)
> - `@swc/html` - remove and collapse whitespaces only in safe places (for example - around `html` and `body` elements, inside the `head` element and between metadata elements - `<meta>`/`script`/`link`/etc.)
## Options

@@ -260,2 +298,8 @@

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.

@@ -410,2 +454,43 @@

## Examples
### `swc/html`
```js
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
type: "asset/resource",
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{
context: path.resolve(__dirname, "dist"),
from: "./src/*.html",
},
],
}),
],
optimization: {
minimize: true,
minimizer: [
new HtmlMinimizerPlugin({
minify: HtmlMinimizerPlugin.swcMinify,
minimizerOptions: {
// Options
},
}),
],
},
};
```
## Contributing

@@ -412,0 +497,0 @@

@@ -138,2 +138,3 @@ export = HtmlMinimizerPlugin;

htmlMinifierTerser,
swcMinify,
Schema,

@@ -193,2 +194,3 @@ Compiler,

import { htmlMinifierTerser } from "./utils";
import { swcMinify } from "./utils";
type Schema = import("schema-utils/declarations/validate").Schema;

@@ -195,0 +197,0 @@ type Compilation = import("webpack").Compilation;

export type Task<T> = () => Promise<T>;
export type MinimizedResult = import("./index.js").MinimizedResult;
export type CustomOptions = import("./index.js").CustomOptions;
export type Input = import("./index.js").Input;

@@ -19,3 +20,3 @@ export type HtmlMinifierTerserOptions = import("html-minifier-terser").Options;

* @param {Input} input
* @param {HtmlMinifierTerserOptions | undefined} [minimizerOptions]
* @param {CustomOptions | undefined} [minimizerOptions]
* @returns {Promise<MinimizedResult>}

@@ -25,3 +26,12 @@ */

input: Input,
minimizerOptions?: HtmlMinifierTerserOptions | undefined
minimizerOptions?: CustomOptions | undefined
): Promise<MinimizedResult>;
/**
* @param {Input} input
* @param {CustomOptions | undefined} [minimizerOptions]
* @returns {Promise<MinimizedResult>}
*/
export function swcMinify(
input: Input,
minimizerOptions?: CustomOptions | undefined
): Promise<MinimizedResult>;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc