html-bundle 6.0.20 → 6.0.22
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/dist/bundle.mjs +7 -2
- package/dist/utils.mjs +5 -1
- package/package.json +5 -5
- package/src/bundle.mts +11 -2
- package/src/utils.mts +22 -2
package/dist/bundle.mjs
CHANGED
|
@@ -19,6 +19,7 @@ const isCritical = process.argv.includes("--isCritical") || bundleConfig.isCriti
|
|
|
19
19
|
const critters = new Critters({
|
|
20
20
|
path: bundleConfig.build,
|
|
21
21
|
logLevel: "silent",
|
|
22
|
+
...bundleConfig.critical,
|
|
22
23
|
});
|
|
23
24
|
const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
|
|
24
25
|
const handlerFile = process.argv.includes("--handler")
|
|
@@ -243,8 +244,9 @@ async function writeInlineScripts(file) {
|
|
|
243
244
|
const script = scripts[index];
|
|
244
245
|
const scriptTextNode = script.childNodes[0];
|
|
245
246
|
const isReferencedScript = script.attrs.find((a) => a.name === "src");
|
|
247
|
+
const type = script.attrs.find((a) => a.name === "type");
|
|
246
248
|
const scriptContent = scriptTextNode?.value;
|
|
247
|
-
if (!scriptContent || isReferencedScript)
|
|
249
|
+
if (!scriptContent || isReferencedScript || type?.value === "importmap")
|
|
248
250
|
continue;
|
|
249
251
|
const jsFile = file.replace(".html", `-bundle-${index}.tsx`);
|
|
250
252
|
inlineFiles.add(jsFile);
|
|
@@ -273,7 +275,10 @@ async function minifyHTML(file, buildFile) {
|
|
|
273
275
|
const script = scripts[index];
|
|
274
276
|
const scriptTextNode = script.childNodes[0];
|
|
275
277
|
const isReferencedScript = script.attrs.find((a) => a.name === "src");
|
|
276
|
-
|
|
278
|
+
const type = script.attrs.find((a) => a.name === "type");
|
|
279
|
+
if (!scriptTextNode?.value ||
|
|
280
|
+
isReferencedScript ||
|
|
281
|
+
type?.value === "importmap")
|
|
277
282
|
continue;
|
|
278
283
|
// Use bundled file
|
|
279
284
|
const buildInlineScript = buildFile.replace(".html", `-bundle-${index}.js`);
|
package/dist/utils.mjs
CHANGED
|
@@ -71,8 +71,12 @@ async function getBundleConfig() {
|
|
|
71
71
|
port: 5000,
|
|
72
72
|
esbuild: {},
|
|
73
73
|
"html-minifier-terser": {},
|
|
74
|
-
critical: {},
|
|
75
74
|
deletePrev: true,
|
|
75
|
+
critical: {},
|
|
76
|
+
isCritical: false,
|
|
77
|
+
hmr: false,
|
|
78
|
+
secure: false,
|
|
79
|
+
handler: "",
|
|
76
80
|
};
|
|
77
81
|
try {
|
|
78
82
|
const cfgPath = path.resolve(process.cwd(), "bundle.config.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-bundle",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.22",
|
|
4
4
|
"description": "A very simple bundler for HTML SFC",
|
|
5
5
|
"bin": "./dist/bundle.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"await-spawn": "^4.0.2",
|
|
37
37
|
"chokidar": "^3.5.3",
|
|
38
38
|
"critters": "^0.0.20",
|
|
39
|
-
"cssnano": "^6.0.
|
|
40
|
-
"esbuild": "^0.19.
|
|
41
|
-
"fastify": "^4.25.
|
|
39
|
+
"cssnano": "^6.0.3",
|
|
40
|
+
"esbuild": "^0.19.11",
|
|
41
|
+
"fastify": "^4.25.2",
|
|
42
42
|
"glob": "^10.3.10",
|
|
43
43
|
"html-minifier-terser": "^7.2.0",
|
|
44
44
|
"hydro-js": "^1.5.14",
|
|
45
45
|
"parse5": "^7.1.2",
|
|
46
|
-
"postcss": "^8.4.
|
|
46
|
+
"postcss": "^8.4.33",
|
|
47
47
|
"postcss-load-config": "^5.0.2"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/bundle.mts
CHANGED
|
@@ -33,6 +33,7 @@ const isCritical =
|
|
|
33
33
|
const critters = new Critters({
|
|
34
34
|
path: bundleConfig.build,
|
|
35
35
|
logLevel: "silent",
|
|
36
|
+
...bundleConfig.critical,
|
|
36
37
|
});
|
|
37
38
|
const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
|
|
38
39
|
const handlerFile = process.argv.includes("--handler")
|
|
@@ -292,8 +293,10 @@ async function writeInlineScripts(file: string) {
|
|
|
292
293
|
const isReferencedScript = script.attrs.find(
|
|
293
294
|
(a: { name: string }) => a.name === "src"
|
|
294
295
|
);
|
|
296
|
+
const type = script.attrs.find((a: { name: string }) => a.name === "type");
|
|
295
297
|
const scriptContent = scriptTextNode?.value;
|
|
296
|
-
if (!scriptContent || isReferencedScript)
|
|
298
|
+
if (!scriptContent || isReferencedScript || type?.value === "importmap")
|
|
299
|
+
continue;
|
|
297
300
|
|
|
298
301
|
const jsFile = file.replace(".html", `-bundle-${index}.tsx`);
|
|
299
302
|
inlineFiles.add(jsFile);
|
|
@@ -326,7 +329,13 @@ async function minifyHTML(file: string, buildFile: string) {
|
|
|
326
329
|
const isReferencedScript = script.attrs.find(
|
|
327
330
|
(a: { name: string }) => a.name === "src"
|
|
328
331
|
);
|
|
329
|
-
|
|
332
|
+
const type = script.attrs.find((a: { name: string }) => a.name === "type");
|
|
333
|
+
if (
|
|
334
|
+
!scriptTextNode?.value ||
|
|
335
|
+
isReferencedScript ||
|
|
336
|
+
type?.value === "importmap"
|
|
337
|
+
)
|
|
338
|
+
continue;
|
|
330
339
|
|
|
331
340
|
// Use bundled file
|
|
332
341
|
const buildInlineScript = buildFile.replace(".html", `-bundle-${index}.js`);
|
package/src/utils.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { Options as HTMLOptions } from "html-minifier-terser";
|
|
2
|
+
import type { Options } from "critters";
|
|
3
|
+
import type { BuildOptions } from "esbuild";
|
|
1
4
|
import type { Node } from "@web/parse5-utils";
|
|
2
5
|
import type { FastifyServerOptions } from "fastify";
|
|
3
6
|
import { copyFile, mkdir, readFile } from "fs/promises";
|
|
@@ -86,15 +89,32 @@ export async function getPostCSSConfig() {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
export type Config = {
|
|
93
|
+
build: string;
|
|
94
|
+
src: string;
|
|
95
|
+
port: number;
|
|
96
|
+
secure: boolean;
|
|
97
|
+
esbuild?: BuildOptions;
|
|
98
|
+
"html-minifier-terser"?: HTMLOptions;
|
|
99
|
+
critical?: Options;
|
|
100
|
+
deletePrev?: boolean;
|
|
101
|
+
isCritical?: boolean;
|
|
102
|
+
hmr?: boolean;
|
|
103
|
+
handler?: string;
|
|
104
|
+
};
|
|
105
|
+
async function getBundleConfig(): Promise<Config> {
|
|
90
106
|
const base = {
|
|
91
107
|
build: "build",
|
|
92
108
|
src: "src",
|
|
93
109
|
port: 5000,
|
|
94
110
|
esbuild: {},
|
|
95
111
|
"html-minifier-terser": {},
|
|
96
|
-
critical: {},
|
|
97
112
|
deletePrev: true,
|
|
113
|
+
critical: {},
|
|
114
|
+
isCritical: false,
|
|
115
|
+
hmr: false,
|
|
116
|
+
secure: false,
|
|
117
|
+
handler: "",
|
|
98
118
|
};
|
|
99
119
|
|
|
100
120
|
try {
|