@jsenv/plugin-minification 1.7.13 → 1.7.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-minification",
3
- "version": "1.7.13",
3
+ "version": "1.7.14",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,7 +24,7 @@
24
24
  "@jsenv/ast": "6.10.0",
25
25
  "@jsenv/sourcemap": "1.4.3",
26
26
  "@jsenv/urls": "2.9.10",
27
- "html-minifier": "4.0.0",
27
+ "html-minifier-terser": "7.2.0",
28
28
  "lightningcss": "1.33.0",
29
29
  "terser": "5.49.0"
30
30
  },
@@ -1,9 +1,6 @@
1
- import { createRequire } from "node:module";
2
-
3
- // https://github.com/kangax/html-minifier#options-quick-reference
4
- export const minifyHtml = (htmlUrlInfo, options = {}) => {
5
- const require = createRequire(import.meta.url);
6
- const { minify } = require("html-minifier");
1
+ // https://github.com/terser/html-minifier-terser#options-quick-reference
2
+ export const minifyHtml = async (htmlUrlInfo, options = {}) => {
3
+ const { minify } = await import("html-minifier-terser");
7
4
 
8
5
  const {
9
6
  // usually HTML will contain a few markup, it's better to keep white spaces
@@ -16,13 +13,21 @@ export const minifyHtml = (htmlUrlInfo, options = {}) => {
16
13
  preserveLineBreaks = true,
17
14
  removeComments = true,
18
15
  conservativeCollapse = false,
16
+ // comments are sometimes meaningful to whoever reads the HTML after the build:
17
+ // a server injecting content at a marker, an SSI directive, a legal banner, ...
18
+ // these are kept even when removeComments is true.
19
+ // the comment text (without "<!--" and "-->") is tested against each regexp
20
+ // "<!--! ... -->" -> legal/banner comments, same convention as CSS and JS minifiers
21
+ // "<!--# ... -->" -> server side includes
22
+ keepComments = [/^!/, /^\s*#/],
19
23
  } = options;
20
24
 
21
- const htmlMinified = minify(htmlUrlInfo.content, {
25
+ const htmlMinified = await minify(htmlUrlInfo.content, {
22
26
  collapseWhitespace,
23
27
  conservativeCollapse,
24
28
  removeComments,
25
29
  preserveLineBreaks,
30
+ ignoreCustomComments: keepComments,
26
31
  });
27
32
  return htmlMinified;
28
33
  };