html-bundle 6.0.2 → 6.0.6

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
  }
@@ -204,11 +206,11 @@ async function minifyCode() {
204
206
  missingPkg = true;
205
207
  const packageNameRegex = /(?<=").*(?=")/;
206
208
  const [pkgName] = error.text.match(packageNameRegex);
207
- console.log(`📦 Package ${pkgName} was installed for you`);
208
209
  await awaitSpawn(process.platform === "win32" ? "npm.cmd" : "npm", [
209
210
  "install",
210
211
  pkgName,
211
212
  ]);
213
+ console.log(`📦 Package ${pkgName} was installed for you`);
212
214
  }
213
215
  }
214
216
  if (missingPkg) {
package/dist/utils.mjs CHANGED
@@ -164,8 +164,6 @@ function getHMRCode(file, id, src) {
164
164
  if (dataObj.html.includes("<script")) updateElem("script");
165
165
 
166
166
 
167
- console.log("dispatch")
168
- console.log(dataObj.file)
169
167
  if (dataObj.file === \`${src}/index.html\`) {
170
168
  dispatchEvent(new Event("popstate"));
171
169
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-bundle",
3
- "version": "6.0.2",
3
+ "version": "6.0.6",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "scripts": {
@@ -18,7 +18,7 @@
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",
@@ -36,13 +36,14 @@
36
36
  "chokidar": "^3.5.2",
37
37
  "critical": "^4.0.1",
38
38
  "cssnano": "^5.0.14",
39
- "esbuild": "^0.14.8",
40
- "fastify": "^3.25.2",
39
+ "esbuild": "^0.14.10",
40
+ "fastify": "^3.25.3",
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.7",
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 {
@@ -243,12 +245,13 @@ async function minifyCode(): Promise<unknown> {
243
245
  missingPkg = true;
244
246
  const packageNameRegex = /(?<=").*(?=")/;
245
247
  const [pkgName] = error.text.match(packageNameRegex);
246
- console.log(`📦 Package ${pkgName} was installed for you`);
247
248
 
248
249
  await awaitSpawn(process.platform === "win32" ? "npm.cmd" : "npm", [
249
250
  "install",
250
251
  pkgName,
251
252
  ]);
253
+
254
+ console.log(`📦 Package ${pkgName} was installed for you`);
252
255
  }
253
256
  }
254
257