Skip to content

Commit f88a0b9

Browse files
committed
work
1 parent b693d79 commit f88a0b9

13 files changed

Lines changed: 62 additions & 31 deletions

File tree

docs/users/c_build/c_build.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,12 @@ Minification reduces file size and is enabled by default.
475475

476476
The minifiers used are:
477477

478-
| File type | Minifier used |
479-
| ------------------------ | -------------------------------------------------------------------------- |
480-
| js module and js classic | [terser](https://github.com/terser/terser)<sup>↗</sup> |
481-
| html and svg | [html-minifier](https://github.com/kangax/html-minifier)<sup>↗</sup> |
482-
| css | [lightningcss](https://github.com/parcel-bundler/lightningcss)<sup>↗</sup> |
483-
| json | White spaces are removed using JSON.stringify |
478+
| File type | Minifier used |
479+
| ------------------------ | ---------------------------------------------------------------------------------- |
480+
| js module and js classic | [terser](https://github.com/terser/terser)<sup>↗</sup> |
481+
| html and svg | [html-minifier-terser](https://github.com/terser/html-minifier-terser)<sup>↗</sup> |
482+
| css | [lightningcss](https://github.com/parcel-bundler/lightningcss)<sup>↗</sup> |
483+
| json | White spaces are removed using JSON.stringify |
484484

485485
You can configure which files to minify:
486486

@@ -507,6 +507,32 @@ await build({
507507

508508
To disable minification, use `minification: false`.
509509

510+
### HTML comments
511+
512+
HTML is minified with comments removed. Some comments are meaningful after the
513+
build though: a marker a server looks for to inject content, a server side
514+
include, a legal banner. These are preserved:
515+
516+
```html
517+
<!--! kept: starts with "!" -->
518+
<!--# kept: server side include -->
519+
<!-- removed -->
520+
```
521+
522+
Use `keepComments` to change which comments survive; the comment text, without
523+
`<!--` and `-->`, is tested against each regexp:
524+
525+
```js
526+
minification: {
527+
html: {
528+
// keep "<!-- INJECT_HERE -->" on top of the default ones
529+
keepComments: [/^!/, /^\s*#/, /INJECT/],
530+
},
531+
},
532+
```
533+
534+
Use `html: { removeComments: false }` to keep every comment.
535+
510536
## 2.5 Build urls
511537

512538
By default, URLs in the build are absolute and versioned:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsenv/core",
3-
"version": "41.5.0",
3+
"version": "41.5.1",
44
"type": "module",
55
"description": "Tool to develop, test and build js projects",
66
"repository": {
@@ -76,7 +76,7 @@
7676
"@jsenv/ast": "6.10.0",
7777
"@jsenv/js-module-fallback": "1.6.0",
7878
"@jsenv/plugin-bundling": "2.10.20",
79-
"@jsenv/plugin-minification": "1.7.13",
79+
"@jsenv/plugin-minification": "1.7.14",
8080
"@jsenv/plugin-supervisor": "1.8.16",
8181
"@jsenv/plugin-transpilation": "1.7.0",
8282
"@jsenv/server": "17.6.3",

packages/internal/plugin-minification/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsenv/plugin-minification",
3-
"version": "1.7.13",
3+
"version": "1.7.14",
44
"type": "module",
55
"repository": {
66
"type": "git",
@@ -24,7 +24,7 @@
2424
"@jsenv/ast": "6.10.0",
2525
"@jsenv/sourcemap": "1.4.3",
2626
"@jsenv/urls": "2.9.10",
27-
"html-minifier": "4.0.0",
27+
"html-minifier-terser": "7.2.0",
2828
"lightningcss": "1.33.0",
2929
"terser": "5.49.0"
3030
},
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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");
74

85
const {
96
// usually HTML will contain a few markup, it's better to keep white spaces
@@ -16,13 +13,21 @@ export const minifyHtml = (htmlUrlInfo, options = {}) => {
1613
preserveLineBreaks = true,
1714
removeComments = true,
1815
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*#/],
1923
} = options;
2024

21-
const htmlMinified = minify(htmlUrlInfo.content, {
25+
const htmlMinified = await minify(htmlUrlInfo.content, {
2226
collapseWhitespace,
2327
conservativeCollapse,
2428
removeComments,
2529
preserveLineBreaks,
30+
ignoreCustomComments: keepComments,
2631
});
2732
return htmlMinified;
2833
};

packages/related/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsenv/cli",
3-
"version": "0.3.161",
3+
"version": "0.3.162",
44
"type": "module",
55
"description": "Command Line Interface for jsenv",
66
"repository": {

packages/related/cli/template-node-package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@jsenv/assert": "4.5.7",
16-
"@jsenv/core": "41.5.0",
16+
"@jsenv/core": "41.5.1",
1717
"@jsenv/eslint-config-relax": "2.0.0",
1818
"@jsenv/test": "3.7.39",
1919
"eslint": "10.9.1",

packages/related/cli/template-web-components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"devDependencies": {
1818
"@jsenv/custom-elements-redefine": "0.1.0",
1919
"@jsenv/assert": "4.5.7",
20-
"@jsenv/core": "41.5.0",
20+
"@jsenv/core": "41.5.1",
2121
"@jsenv/plugin-bundling": "2.10.20",
22-
"@jsenv/plugin-minification": "1.7.13",
22+
"@jsenv/plugin-minification": "1.7.14",
2323
"@jsenv/eslint-config-relax": "2.0.0",
2424
"@jsenv/test": "3.7.39",
2525
"eslint": "10.9.1",

packages/related/cli/template-web-preact/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"devDependencies": {
2121
"@babel/plugin-transform-react-jsx": "8.0.1",
2222
"@jsenv/assert": "4.5.7",
23-
"@jsenv/core": "41.5.0",
23+
"@jsenv/core": "41.5.1",
2424
"@jsenv/plugin-preact": "1.9.0",
2525
"@jsenv/plugin-bundling": "2.10.20",
26-
"@jsenv/plugin-minification": "1.7.13",
26+
"@jsenv/plugin-minification": "1.7.14",
2727
"@jsenv/eslint-config-relax": "2.0.0",
2828
"@jsenv/test": "3.7.39",
2929
"eslint": "10.9.1",

packages/related/cli/template-web-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"devDependencies": {
2222
"@babel/plugin-transform-react-jsx": "8.0.1",
2323
"@jsenv/assert": "4.5.7",
24-
"@jsenv/core": "41.5.0",
24+
"@jsenv/core": "41.5.1",
2525
"@jsenv/plugin-react": "1.9.0",
2626
"@jsenv/plugin-bundling": "2.10.20",
27-
"@jsenv/plugin-minification": "1.7.13",
27+
"@jsenv/plugin-minification": "1.7.14",
2828
"@jsenv/eslint-config-relax": "2.0.0",
2929
"@jsenv/test": "3.7.39",
3030
"eslint": "10.9.1",

packages/related/cli/template-web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
},
1616
"devDependencies": {
1717
"@jsenv/assert": "4.5.7",
18-
"@jsenv/core": "41.5.0",
18+
"@jsenv/core": "41.5.1",
1919
"@jsenv/eslint-config-relax": "2.0.0",
2020
"@jsenv/plugin-bundling": "2.10.20",
21-
"@jsenv/plugin-minification": "1.7.13",
21+
"@jsenv/plugin-minification": "1.7.14",
2222
"@jsenv/test": "3.7.39",
2323
"eslint": "10.9.1",
2424
"open": "11.0.1",

0 commit comments

Comments
 (0)