html-bundle 6.0.3 → 6.0.7

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
@@ -47,7 +47,7 @@ $ npm run build
47
47
 
48
48
  `--hmr`: boots up a static server and enables Hot Module Replacement. **This generates a development build and works best when not triggered from the main index.html**<br>
49
49
  `--secure`: creates a secure HTTP2 over HTTPS instance. This requires the files `localhost.pem` and `localhost-key.pem` in the root folder. You can generate them with [mkcert](https://github.com/FiloSottile/mkcert) for instance.<br>
50
- `--critical`: uses critical to extract and inline critical-path CSS to HTML.<br>
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
53
  ## Optional Config
@@ -65,7 +65,7 @@ Generate the config in the root and call it "bundle.config.js"
65
65
 
66
66
  ## Concept
67
67
 
68
- The bundler always globs all HTML, CSS and TS/JS files from the `src` (config) directory and processes them to the `build` (config) directory. PostCSS is being used for CSS files and inline styles, html-minifier-terser for HTML and esbuild to bundle, minify, etc. for inline and referenced TS/JS. Server-sent events and [hydro-js](https://github.com/Krutsch/hydro-js) are used for HMR. This will install hydro-js to your dependencies. In order to trigger SPA Routers, the popstate event is being triggered after HMR Operations.
68
+ The bundler always globs all HTML, CSS and TS/JS files from the `src` (config) directory and processes them to the `build` (config) directory. PostCSS is being used for CSS files and inline styles, html-minifier-terser for HTML and esbuild to bundle, minify, etc. for inline and referenced TS/JS. Server-sent events and [hydro-js](https://github.com/Krutsch/hydro-js) are used for HMR. In order to trigger SPA Routers, the popstate event is being triggered after HMR Operations.
69
69
 
70
70
  ## Example hydro-js
71
71
 
package/dist/bundle.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { performance } from "perf_hooks";
3
- import { readFile, rm, writeFile, readdir } from "fs/promises";
3
+ import { readFile, rm, writeFile, readdir, lstat } from "fs/promises";
4
4
  import { execFile } from "child_process";
5
5
  import { promisify } from "util";
6
6
  import glob from "glob";
@@ -14,7 +14,7 @@ import { getTagName, findElements } from "@web/parse5-utils";
14
14
  import awaitSpawn from "await-spawn";
15
15
  import { fileCopy, createDefaultServer, getPostCSSConfig, getBuildPath, createDir, bundleConfig, serverSentEvents, addHMRCode, } from "./utils.mjs";
16
16
  const isHMR = process.argv.includes("--hmr") || bundleConfig.hmr;
17
- const isCritical = process.argv.includes("--critical") || bundleConfig.critical;
17
+ const isCritical = process.argv.includes("--isCritical") || bundleConfig.isCritical;
18
18
  const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
19
19
  const handlerFile = process.argv.includes("--handler")
20
20
  ? process.argv[process.argv.indexOf("--handler") + 1]
@@ -52,6 +52,8 @@ async function build(err, files, firstRun = true) {
52
52
  console.log("📋 Logging Handler: ", String(stdout));
53
53
  }
54
54
  else {
55
+ if ((await lstat(file)).isDirectory())
56
+ continue;
55
57
  await fileCopy(file);
56
58
  }
57
59
  }
package/dist/utils.mjs CHANGED
@@ -207,7 +207,8 @@ function getHMRCode(file, id, src) {
207
207
  for (const key of elem.getAttributeNames()) {
208
208
  clone.setAttribute(key, elem.getAttribute(key));
209
209
  }
210
- clone.setAttribute(attr, elem.getAttribute(attr) + "?v=" + String(Math.random().toFixed(4)).slice(2));
210
+ const attrVal = elem.getAttribute(attr);
211
+ if (attrVal) clone.setAttribute(attr, attrVal + "?v=" + String(Math.random().toFixed(4)).slice(2));
211
212
  render(clone, elem, false);
212
213
  }
213
214
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-bundle",
3
- "version": "6.0.3",
3
+ "version": "6.0.7",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "scripts": {
@@ -18,12 +18,12 @@
18
18
  "author": "Fabian Krutsch <f.krutsch@gmx.de> (https://krutsch.netlify.app/)",
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
- "@types/cssnano": "^4.0.1",
21
+ "@types/cssnano": "^5.0.0",
22
22
  "@types/glob": "^7.2.0",
23
23
  "@types/html-minifier-terser": "^6.1.0",
24
24
  "@types/parse5": "^6.0.3",
25
25
  "@types/postcss-load-config": "^3.0.1",
26
- "typescript": "^4.5.4"
26
+ "typescript": "^4.5.5"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
@@ -33,16 +33,17 @@
33
33
  "dependencies": {
34
34
  "@web/parse5-utils": "^1.3.0",
35
35
  "await-spawn": "^4.0.2",
36
- "chokidar": "^3.5.2",
36
+ "chokidar": "^3.5.3",
37
37
  "critical": "^4.0.1",
38
- "cssnano": "^5.0.14",
39
- "esbuild": "^0.14.9",
40
- "fastify": "^3.25.3",
38
+ "cssnano": "^5.0.16",
39
+ "esbuild": "^0.14.14",
40
+ "fastify": "^3.27.0",
41
41
  "fastify-static": "^4.5.0",
42
42
  "glob": "^7.2.0",
43
43
  "html-minifier-terser": "^6.1.0",
44
+ "hydro-js": "^1.5.10",
44
45
  "parse5": "^6.0.1",
45
46
  "postcss": "^8.4.5",
46
- "postcss-load-config": "^3.1.0"
47
+ "postcss-load-config": "^3.1.1"
47
48
  }
48
49
  }
package/src/bundle.mts CHANGED
@@ -3,7 +3,7 @@
3
3
  import type { TextNode } from "parse5";
4
4
  import type { AcceptedPlugin } from "postcss";
5
5
  import { performance } from "perf_hooks";
6
- import { readFile, rm, writeFile, readdir } from "fs/promises";
6
+ import { readFile, rm, writeFile, readdir, lstat } from "fs/promises";
7
7
  import { execFile } from "child_process";
8
8
  import { promisify } from "util";
9
9
  import glob from "glob";
@@ -27,7 +27,8 @@ import {
27
27
  } from "./utils.mjs";
28
28
 
29
29
  const isHMR = process.argv.includes("--hmr") || bundleConfig.hmr;
30
- const isCritical = process.argv.includes("--critical") || bundleConfig.critical;
30
+ const isCritical =
31
+ process.argv.includes("--isCritical") || bundleConfig.isCritical;
31
32
  const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
32
33
  const handlerFile = process.argv.includes("--handler")
33
34
  ? process.argv[process.argv.indexOf("--handler") + 1]
@@ -70,6 +71,7 @@ async function build(err: any, files: string[], firstRun = true) {
70
71
  const { stdout } = await execFilePromise("node", [handlerFile, file]);
71
72
  if (String(stdout)) console.log("📋 Logging Handler: ", String(stdout));
72
73
  } else {
74
+ if ((await lstat(file)).isDirectory()) continue;
73
75
  await fileCopy(file);
74
76
  }
75
77
  } else {
package/src/utils.mts CHANGED
@@ -243,7 +243,8 @@ function getHMRCode(file: string, id: string, src: string) {
243
243
  for (const key of elem.getAttributeNames()) {
244
244
  clone.setAttribute(key, elem.getAttribute(key));
245
245
  }
246
- clone.setAttribute(attr, elem.getAttribute(attr) + "?v=" + String(Math.random().toFixed(4)).slice(2));
246
+ const attrVal = elem.getAttribute(attr);
247
+ if (attrVal) clone.setAttribute(attr, attrVal + "?v=" + String(Math.random().toFixed(4)).slice(2));
247
248
  render(clone, elem, false);
248
249
  }
249
250
  });