html-bundle 6.2.0 → 6.2.2

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 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
@@ -258,7 +258,10 @@ async function writeInlineScripts(file) {
258
258
  const isReferencedScript = script.attrs.find((a) => a.name === "src");
259
259
  const type = script.attrs.find((a) => a.name === "type");
260
260
  const scriptContent = scriptTextNode?.value;
261
- if (!scriptContent || isReferencedScript || type?.value === "importmap")
261
+ if (!scriptContent ||
262
+ isReferencedScript ||
263
+ type?.value === "importmap" ||
264
+ type?.value === "application/ld+json")
262
265
  continue;
263
266
  const jsFile = file.replace(".html", `-bundle-${index}.tsx`);
264
267
  inlineFiles.add(jsFile);
@@ -290,7 +293,8 @@ async function minifyHTML(file, buildFile) {
290
293
  const type = script.attrs.find((a) => a.name === "type");
291
294
  if (!scriptTextNode?.value ||
292
295
  isReferencedScript ||
293
- type?.value === "importmap")
296
+ type?.value === "importmap" ||
297
+ type?.value === "application/ld+json")
294
298
  continue;
295
299
  // Use bundled file
296
300
  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.0",
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": "^8.1.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.3.4",
45
- "chokidar": "^4.0.3",
46
- "cssnano": "^7.0.7",
47
- "esbuild": "^0.25.5",
48
- "express": "^5.1.0",
49
- "glob": "^11.0.2",
50
- "html-minifier-terser": "^7.2.0",
51
- "hydro-js": "^1.8.8",
52
- "parse5": "^7.3.0",
53
- "postcss": "^8.5.4",
54
- "postcss-load-config": "^6.0.1"
55
- }
56
- }
1
+ {
2
+ "name": "html-bundle",
3
+ "version": "6.2.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": "^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,11 +305,16 @@ 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;
312
- if (!scriptContent || isReferencedScript || type?.value === "importmap")
312
+ if (
313
+ !scriptContent ||
314
+ isReferencedScript ||
315
+ type?.value === "importmap" ||
316
+ type?.value === "application/ld+json"
317
+ )
313
318
  continue;
314
319
 
315
320
  const jsFile = file.replace(".html", `-bundle-${index}.tsx`);
@@ -341,13 +346,14 @@ async function minifyHTML(file: string, buildFile: string) {
341
346
  const script = scripts[index];
342
347
  const scriptTextNode = script.childNodes[0] as TextNode;
343
348
  const isReferencedScript = script.attrs.find(
344
- (a: { name: string }) => a.name === "src"
349
+ (a: { name: string }) => a.name === "src",
345
350
  );
346
351
  const type = script.attrs.find((a: { name: string }) => a.name === "type");
347
352
  if (
348
353
  !scriptTextNode?.value ||
349
354
  isReferencedScript ||
350
- type?.value === "importmap"
355
+ type?.value === "importmap" ||
356
+ type?.value === "application/ld+json"
351
357
  )
352
358
  continue;
353
359
 
@@ -361,7 +367,7 @@ async function minifyHTML(file: string, buildFile: string) {
361
367
  await rm(buildInlineScript);
362
368
  scriptTextNode.value = scriptContent.replace(
363
369
  TEMPLATE_LITERAL_MINIFIER,
364
- " "
370
+ " ",
365
371
  );
366
372
  } catch {}
367
373
  }