html-bundle 6.1.6 → 6.1.8

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
@@ -12,7 +12,7 @@ A (primarily) zero-config bundler for HTML files. The idea is to use HTML as Sin
12
12
  - 📦 Automatic Package Installation
13
13
  - 💨 HMR and automatic reconnect
14
14
  - ⚡ [ESBuild](https://github.com/evanw/esbuild)
15
- - 🦔 [Critical CSS](https://www.npmjs.com/package/critters)
15
+ - 🦔 [Critical CSS](https://www.npmjs.com/package/beasties)
16
16
  - 🚋 Watcher on PostCSS and Tailwind CSS and TS Config
17
17
  - 🛡️ Almost no need to restart
18
18
 
package/dist/bundle.mjs CHANGED
@@ -7,7 +7,7 @@ import { sep } from "path";
7
7
  import { glob } from "glob";
8
8
  import postcss from "postcss";
9
9
  import esbuild from "esbuild";
10
- import Critters from "critters";
10
+ import Beasties from "beasties";
11
11
  import { minify } from "html-minifier-terser";
12
12
  import { watch } from "chokidar";
13
13
  import { serialize, parse, parseFragment } from "parse5";
@@ -16,7 +16,7 @@ import awaitSpawn from "await-spawn";
16
16
  import { fileCopy, createDefaultServer, getPostCSSConfig, getBuildPath, createDir, bundleConfig, serverSentEvents, addHMRCode, } from "./utils.mjs";
17
17
  const isHMR = process.argv.includes("--hmr") || bundleConfig.hmr;
18
18
  const isCritical = process.argv.includes("--isCritical") || bundleConfig.isCritical;
19
- const critters = new Critters({
19
+ const beasties = new Beasties({
20
20
  path: bundleConfig.build,
21
21
  logLevel: "silent",
22
22
  ...bundleConfig.critical,
@@ -336,8 +336,8 @@ async function minifyHTML(file, buildFile) {
336
336
  if (isCritical) {
337
337
  try {
338
338
  const isPartical = !fileText.startsWith("<!DOCTYPE html>");
339
- fileText = await critters.process(fileText);
340
- // fix critters jsdom
339
+ fileText = await beasties.process(fileText);
340
+ // fix beasties jsdom
341
341
  if (isPartical) {
342
342
  fileText = fileText.replace(/<\/?(html|head|body)>/g, "");
343
343
  }
package/dist/utils.mjs CHANGED
@@ -125,7 +125,9 @@ function getHMRCode(file, id, src) {
125
125
  }, 1000);
126
126
  });
127
127
  window.eventsource${id}.addEventListener("message", ({ data }) => {
128
- window.lastScroll = window.scrollY;
128
+ if (window.lastScroll == null) {
129
+ window.lastScroll = window.scrollY;
130
+ }
129
131
  const dataObj = JSON.parse(data);
130
132
  const file = "${file}";
131
133
 
@@ -141,10 +143,14 @@ function getHMRCode(file, id, src) {
141
143
 
142
144
  if (dataObj.html.startsWith('<!DOCTYPE html>') || dataObj.html.startsWith('<html')) {
143
145
  document.head.remove(); // Don't try to diff the head – just re-run the scripts
144
- render(newHTML, document.documentElement, false);
145
- setTimeout(() => {
146
+
147
+ // Restore Scroll
148
+ window.addEventListener("afterRouting", () => {
146
149
  window.scrollTo(0, window.lastScroll);
147
- }, 50);
150
+ delete window.lastScroll;
151
+ }, { once: true })
152
+
153
+ render(newHTML, document.documentElement, false);
148
154
  } else {
149
155
  const hmrID = "${id}";
150
156
  const hmrElems = Array.from(newHTML.childNodes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-bundle",
3
- "version": "6.1.6",
3
+ "version": "6.1.8",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "types": "./src/config.d.ts",
@@ -19,12 +19,12 @@
19
19
  "author": "Fabian Klingenberg <klingenberg.fabian@gmx.de> (https://klingenberg.netlify.app/)",
20
20
  "license": "MIT",
21
21
  "devDependencies": {
22
- "@types/cssnano": "^5.1.0",
22
+ "@types/cssnano": "^5.1.3",
23
23
  "@types/glob": "^8.1.0",
24
24
  "@types/html-minifier-terser": "^7.0.2",
25
25
  "@types/parse5": "^7.0.0",
26
26
  "@types/postcss-load-config": "^3.0.1",
27
- "typescript": "^5.6.2"
27
+ "typescript": "^5.6.3"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
@@ -32,18 +32,18 @@
32
32
  },
33
33
  "bugs": "https://github.com/Krutsch/html-bundle/issues",
34
34
  "dependencies": {
35
- "@fastify/static": "^8.0.0",
35
+ "@fastify/static": "^8.0.2",
36
36
  "@web/parse5-utils": "^2.1.0",
37
37
  "await-spawn": "^4.0.2",
38
- "chokidar": "^4.0.0",
39
- "critters": "^0.0.24",
38
+ "beasties": "^0.1.0",
39
+ "chokidar": "^4.0.1",
40
40
  "cssnano": "^7.0.6",
41
- "esbuild": "^0.23.1",
41
+ "esbuild": "^0.24.0",
42
42
  "fastify": "^5.0.0",
43
43
  "glob": "^11.0.0",
44
44
  "html-minifier-terser": "^7.2.0",
45
- "hydro-js": "^1.5.19",
46
- "parse5": "^7.1.2",
45
+ "hydro-js": "^1.5.22",
46
+ "parse5": "^7.2.0",
47
47
  "postcss": "^8.4.47",
48
48
  "postcss-load-config": "^6.0.1"
49
49
  }
package/src/bundle.mts CHANGED
@@ -10,7 +10,7 @@ import { sep } from "path";
10
10
  import { glob } from "glob";
11
11
  import postcss from "postcss";
12
12
  import esbuild from "esbuild";
13
- import Critters from "critters";
13
+ import Beasties from "beasties";
14
14
  import { minify } from "html-minifier-terser";
15
15
  import { watch } from "chokidar";
16
16
  import { serialize, parse, parseFragment } from "parse5";
@@ -30,7 +30,7 @@ import {
30
30
  const isHMR = process.argv.includes("--hmr") || bundleConfig.hmr;
31
31
  const isCritical =
32
32
  process.argv.includes("--isCritical") || bundleConfig.isCritical;
33
- const critters = new Critters({
33
+ const beasties = new Beasties({
34
34
  path: bundleConfig.build,
35
35
  logLevel: "silent",
36
36
  ...bundleConfig.critical,
@@ -398,8 +398,8 @@ async function minifyHTML(file: string, buildFile: string) {
398
398
  if (isCritical) {
399
399
  try {
400
400
  const isPartical = !fileText.startsWith("<!DOCTYPE html>");
401
- fileText = await critters.process(fileText);
402
- // fix critters jsdom
401
+ fileText = await beasties.process(fileText);
402
+ // fix beasties jsdom
403
403
  if (isPartical) {
404
404
  fileText = fileText.replace(/<\/?(html|head|body)>/g, "");
405
405
  }
package/src/utils.mts CHANGED
@@ -1,6 +1,3 @@
1
- import type { Options as HTMLOptions } from "html-minifier-terser";
2
- import type { Options } from "critters";
3
- import type { BuildOptions } from "esbuild";
4
1
  import type { Node } from "@web/parse5-utils";
5
2
  import type { FastifyServerOptions } from "fastify";
6
3
  import { copyFile, mkdir, readFile } from "fs/promises";
@@ -168,7 +165,9 @@ function getHMRCode(file: string, id: string, src: string) {
168
165
  }, 1000);
169
166
  });
170
167
  window.eventsource${id}.addEventListener("message", ({ data }) => {
171
- window.lastScroll = window.scrollY;
168
+ if (window.lastScroll == null) {
169
+ window.lastScroll = window.scrollY;
170
+ }
172
171
  const dataObj = JSON.parse(data);
173
172
  const file = "${file}";
174
173
 
@@ -184,10 +183,14 @@ function getHMRCode(file: string, id: string, src: string) {
184
183
 
185
184
  if (dataObj.html.startsWith('<!DOCTYPE html>') || dataObj.html.startsWith('<html')) {
186
185
  document.head.remove(); // Don't try to diff the head – just re-run the scripts
187
- render(newHTML, document.documentElement, false);
188
- setTimeout(() => {
186
+
187
+ // Restore Scroll
188
+ window.addEventListener("afterRouting", () => {
189
189
  window.scrollTo(0, window.lastScroll);
190
- }, 50);
190
+ delete window.lastScroll;
191
+ }, { once: true })
192
+
193
+ render(newHTML, document.documentElement, false);
191
194
  } else {
192
195
  const hmrID = "${id}";
193
196
  const hmrElems = Array.from(newHTML.childNodes);