html-bundle 6.2.0 → 6.2.1
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/README.md +11 -0
- package/dist/bundle.mjs +2 -1
- package/package.json +56 -56
- package/src/bundle.mts +11 -10
package/README.md
CHANGED
|
@@ -50,6 +50,17 @@ $ npm run build
|
|
|
50
50
|
`--isCritical`: uses critical to extract and inline critical-path CSS to HTML.<br>
|
|
51
51
|
`--handler`: path to your custom handler. Here, you can handle all non-supported files. You can get the filename via `process.argv[2]`.
|
|
52
52
|
|
|
53
|
+
## import
|
|
54
|
+
It is also possible to start the server by importing the package. This could be useful, if you intend to add routes for local development.
|
|
55
|
+
```js
|
|
56
|
+
import router from "html-bundle";
|
|
57
|
+
|
|
58
|
+
router.get("/test", (_req, reply) => {
|
|
59
|
+
return reply.send("hi");
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
53
64
|
## Optional Config
|
|
54
65
|
|
|
55
66
|
_The CLI flags can also be set by the config. Flags set by the CLI will override the config._
|
package/dist/bundle.mjs
CHANGED
|
@@ -290,7 +290,8 @@ async function minifyHTML(file, buildFile) {
|
|
|
290
290
|
const type = script.attrs.find((a) => a.name === "type");
|
|
291
291
|
if (!scriptTextNode?.value ||
|
|
292
292
|
isReferencedScript ||
|
|
293
|
-
type?.value === "importmap"
|
|
293
|
+
type?.value === "importmap" ||
|
|
294
|
+
type?.value === "application/ld+json")
|
|
294
295
|
continue;
|
|
295
296
|
// Use bundled file
|
|
296
297
|
const buildInlineScript = buildFile.replace(".html", `-bundle-${index}.js`);
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "html-bundle",
|
|
3
|
-
"version": "6.2.
|
|
4
|
-
"description": "A very simple bundler for HTML SFC",
|
|
5
|
-
"bin": "./dist/bundle.mjs",
|
|
6
|
-
"main": "./dist/bundle.mjs",
|
|
7
|
-
"module": "./dist/bundle.mjs",
|
|
8
|
-
"exports": {
|
|
9
|
-
"import": "./dist/bundle.mjs",
|
|
10
|
-
"default": "./dist/bundle.mjs"
|
|
11
|
-
},
|
|
12
|
-
"types": "./dist/bundle.d.mts",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"start": "tsc",
|
|
15
|
-
"update": "npx npm-check-updates -u && npx typesync && npm i && npm outdated"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"bundler",
|
|
19
|
-
"SFC",
|
|
20
|
-
"HTML",
|
|
21
|
-
"TypeScript",
|
|
22
|
-
"esbuild",
|
|
23
|
-
"hydro-js"
|
|
24
|
-
],
|
|
25
|
-
"author": "Fabian Klingenberg <klingenberg.fabian@gmx.de> (https://klingenberg.works/)",
|
|
26
|
-
"license": "MIT",
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/cssnano": "^5.1.3",
|
|
29
|
-
"@types/express": "~5.0.2",
|
|
30
|
-
"@types/glob": "^
|
|
31
|
-
"@types/html-minifier-terser": "^7.0.2",
|
|
32
|
-
"@types/parse5": "^7.0.0",
|
|
33
|
-
"@types/postcss-load-config": "^3.0.1",
|
|
34
|
-
"typescript": "^5.8.3"
|
|
35
|
-
},
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/Krutsch/html-bundle.git"
|
|
39
|
-
},
|
|
40
|
-
"bugs": "https://github.com/Krutsch/html-bundle/issues",
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@web/parse5-utils": "^2.1.0",
|
|
43
|
-
"await-spawn": "^4.0.2",
|
|
44
|
-
"beasties": "^0.
|
|
45
|
-
"chokidar": "^
|
|
46
|
-
"cssnano": "^7.0.7",
|
|
47
|
-
"esbuild": "^0.
|
|
48
|
-
"express": "^5.1.0",
|
|
49
|
-
"glob": "^
|
|
50
|
-
"html-minifier-terser": "^7.2.0",
|
|
51
|
-
"hydro-js": "^1.8.8",
|
|
52
|
-
"parse5": "^
|
|
53
|
-
"postcss": "^8.5.4",
|
|
54
|
-
"postcss-load-config": "^6.0.1"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "html-bundle",
|
|
3
|
+
"version": "6.2.1",
|
|
4
|
+
"description": "A very simple bundler for HTML SFC",
|
|
5
|
+
"bin": "./dist/bundle.mjs",
|
|
6
|
+
"main": "./dist/bundle.mjs",
|
|
7
|
+
"module": "./dist/bundle.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": "./dist/bundle.mjs",
|
|
10
|
+
"default": "./dist/bundle.mjs"
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/bundle.d.mts",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "tsc",
|
|
15
|
+
"update": "npx npm-check-updates -u && npx typesync && npm i && npm outdated"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"bundler",
|
|
19
|
+
"SFC",
|
|
20
|
+
"HTML",
|
|
21
|
+
"TypeScript",
|
|
22
|
+
"esbuild",
|
|
23
|
+
"hydro-js"
|
|
24
|
+
],
|
|
25
|
+
"author": "Fabian Klingenberg <klingenberg.fabian@gmx.de> (https://klingenberg.works/)",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/cssnano": "^5.1.3",
|
|
29
|
+
"@types/express": "~5.0.2",
|
|
30
|
+
"@types/glob": "^9.0.0",
|
|
31
|
+
"@types/html-minifier-terser": "^7.0.2",
|
|
32
|
+
"@types/parse5": "^7.0.0",
|
|
33
|
+
"@types/postcss-load-config": "^3.0.1",
|
|
34
|
+
"typescript": "^5.8.3"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/Krutsch/html-bundle.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": "https://github.com/Krutsch/html-bundle/issues",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@web/parse5-utils": "^2.1.0",
|
|
43
|
+
"await-spawn": "^4.0.2",
|
|
44
|
+
"beasties": "^0.4.0",
|
|
45
|
+
"chokidar": "^5.0.0",
|
|
46
|
+
"cssnano": "^7.0.7",
|
|
47
|
+
"esbuild": "^0.27.0",
|
|
48
|
+
"express": "^5.1.0",
|
|
49
|
+
"glob": "^13.0.0",
|
|
50
|
+
"html-minifier-terser": "^7.2.0",
|
|
51
|
+
"hydro-js": "^1.8.8",
|
|
52
|
+
"parse5": "^8.0.0",
|
|
53
|
+
"postcss": "^8.5.4",
|
|
54
|
+
"postcss-load-config": "^6.0.1"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/bundle.mts
CHANGED
|
@@ -94,7 +94,7 @@ async function build(files: string[], firstRun = true) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
console.log(
|
|
97
|
-
`🚀 Build finished in ${(performance.now() - timer).toFixed(2)}ms
|
|
97
|
+
`🚀 Build finished in ${(performance.now() - timer).toFixed(2)}ms ✨`,
|
|
98
98
|
);
|
|
99
99
|
|
|
100
100
|
if (isHMR && firstRun) {
|
|
@@ -104,7 +104,7 @@ async function build(files: string[], firstRun = true) {
|
|
|
104
104
|
console.log(
|
|
105
105
|
`💻 Server listening on http${isSecure ? "s" : ""}://${
|
|
106
106
|
bundleConfig.host === "::" ? "localhost" : bundleConfig.host
|
|
107
|
-
}:${bundleConfig.port} and is shared in the local network
|
|
107
|
+
}:${bundleConfig.port} and is shared in the local network.`,
|
|
108
108
|
);
|
|
109
109
|
|
|
110
110
|
console.log(`⌛ Waiting for file changes ...`);
|
|
@@ -114,21 +114,21 @@ async function build(files: string[], firstRun = true) {
|
|
|
114
114
|
const postCSSWatcher = watch(postcssFile, chokidarOptions);
|
|
115
115
|
const tailwindCSSWatcher = watch(
|
|
116
116
|
postcssFile.replace("postcss", "tailwind"),
|
|
117
|
-
chokidarOptions
|
|
117
|
+
chokidarOptions,
|
|
118
118
|
); // Assuming that the file ext is the same
|
|
119
119
|
const tsConfigWatcher = watch(
|
|
120
120
|
postcssFile.split("\\").slice(0, -1).join("\\") + "\\tsconfig.json",
|
|
121
|
-
chokidarOptions
|
|
121
|
+
chokidarOptions,
|
|
122
122
|
);
|
|
123
123
|
|
|
124
124
|
const cssFiles = files.filter((file) => file.endsWith(".css"));
|
|
125
125
|
postCSSWatcher.on(
|
|
126
126
|
"change",
|
|
127
|
-
async () => await rebuildCSS(cssFiles, "postcss")
|
|
127
|
+
async () => await rebuildCSS(cssFiles, "postcss"),
|
|
128
128
|
);
|
|
129
129
|
tailwindCSSWatcher.on(
|
|
130
130
|
"change",
|
|
131
|
-
async () => await rebuildCSS(cssFiles, "tailwind")
|
|
131
|
+
async () => await rebuildCSS(cssFiles, "tailwind"),
|
|
132
132
|
);
|
|
133
133
|
tsConfigWatcher.on("change", async () => {
|
|
134
134
|
timer = performance.now();
|
|
@@ -305,7 +305,7 @@ async function writeInlineScripts(file: string) {
|
|
|
305
305
|
const script = scripts[index];
|
|
306
306
|
const scriptTextNode = script.childNodes[0] as TextNode;
|
|
307
307
|
const isReferencedScript = script.attrs.find(
|
|
308
|
-
(a: { name: string }) => a.name === "src"
|
|
308
|
+
(a: { name: string }) => a.name === "src",
|
|
309
309
|
);
|
|
310
310
|
const type = script.attrs.find((a: { name: string }) => a.name === "type");
|
|
311
311
|
const scriptContent = scriptTextNode?.value;
|
|
@@ -341,13 +341,14 @@ async function minifyHTML(file: string, buildFile: string) {
|
|
|
341
341
|
const script = scripts[index];
|
|
342
342
|
const scriptTextNode = script.childNodes[0] as TextNode;
|
|
343
343
|
const isReferencedScript = script.attrs.find(
|
|
344
|
-
(a: { name: string }) => a.name === "src"
|
|
344
|
+
(a: { name: string }) => a.name === "src",
|
|
345
345
|
);
|
|
346
346
|
const type = script.attrs.find((a: { name: string }) => a.name === "type");
|
|
347
347
|
if (
|
|
348
348
|
!scriptTextNode?.value ||
|
|
349
349
|
isReferencedScript ||
|
|
350
|
-
type?.value === "importmap"
|
|
350
|
+
type?.value === "importmap" ||
|
|
351
|
+
type?.value === "application/ld+json"
|
|
351
352
|
)
|
|
352
353
|
continue;
|
|
353
354
|
|
|
@@ -361,7 +362,7 @@ async function minifyHTML(file: string, buildFile: string) {
|
|
|
361
362
|
await rm(buildInlineScript);
|
|
362
363
|
scriptTextNode.value = scriptContent.replace(
|
|
363
364
|
TEMPLATE_LITERAL_MINIFIER,
|
|
364
|
-
" "
|
|
365
|
+
" ",
|
|
365
366
|
);
|
|
366
367
|
} catch {}
|
|
367
368
|
}
|