html-bundle 6.0.19 → 6.0.21

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/dist/bundle.mjs CHANGED
@@ -19,6 +19,7 @@ const isCritical = process.argv.includes("--isCritical") || bundleConfig.isCriti
19
19
  const critters = new Critters({
20
20
  path: bundleConfig.build,
21
21
  logLevel: "silent",
22
+ ...bundleConfig.critical,
22
23
  });
23
24
  const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
24
25
  const handlerFile = process.argv.includes("--handler")
package/dist/utils.mjs CHANGED
@@ -72,7 +72,11 @@ async function getBundleConfig() {
72
72
  esbuild: {},
73
73
  "html-minifier-terser": {},
74
74
  critical: {},
75
+ isCritical: false,
75
76
  deletePrev: true,
77
+ hmr: false,
78
+ secure: false,
79
+ handler: "",
76
80
  };
77
81
  try {
78
82
  const cfgPath = path.resolve(process.cwd(), "bundle.config.js");
@@ -118,6 +122,7 @@ function getHMRCode(file, id, src) {
118
122
  }, 1000);
119
123
  });
120
124
  window.eventsource${id}.addEventListener("message", ({ data }) => {
125
+ window.lastScroll = window.scrollY;
121
126
  const dataObj = JSON.parse(data);
122
127
  const file = "${file}";
123
128
 
@@ -134,6 +139,9 @@ function getHMRCode(file, id, src) {
134
139
  if (dataObj.html.startsWith('<!DOCTYPE html>') || dataObj.html.startsWith('<html')) {
135
140
  document.head.remove(); // Don't try to diff the head – just re-run the scripts
136
141
  render(newHTML, document.documentElement, false);
142
+ setTimeout(() => {
143
+ window.scrollTo(0, window.lastScroll);
144
+ }, 50);
137
145
  } else {
138
146
  const hmrID = "${id}";
139
147
  const hmrElems = Array.from(newHTML.childNodes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-bundle",
3
- "version": "6.0.19",
3
+ "version": "6.0.21",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "scripts": {
@@ -37,8 +37,8 @@
37
37
  "chokidar": "^3.5.3",
38
38
  "critters": "^0.0.20",
39
39
  "cssnano": "^6.0.2",
40
- "esbuild": "^0.19.9",
41
- "fastify": "^4.25.1",
40
+ "esbuild": "^0.19.11",
41
+ "fastify": "^4.25.2",
42
42
  "glob": "^10.3.10",
43
43
  "html-minifier-terser": "^7.2.0",
44
44
  "hydro-js": "^1.5.14",
package/src/bundle.mts CHANGED
@@ -33,6 +33,7 @@ const isCritical =
33
33
  const critters = new Critters({
34
34
  path: bundleConfig.build,
35
35
  logLevel: "silent",
36
+ ...bundleConfig.critical,
36
37
  });
37
38
  const isSecure = process.argv.includes("--secure") || bundleConfig.secure; // uses CSP for critical too
38
39
  const handlerFile = process.argv.includes("--handler")
package/src/utils.mts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { Options as HTMLOptions } from "html-minifier-terser";
2
+ import type { Options } from "critters";
3
+ import type { BuildOptions } from "esbuild";
1
4
  import type { Node } from "@web/parse5-utils";
2
5
  import type { FastifyServerOptions } from "fastify";
3
6
  import { copyFile, mkdir, readFile } from "fs/promises";
@@ -86,15 +89,32 @@ export async function getPostCSSConfig() {
86
89
  }
87
90
  }
88
91
 
89
- async function getBundleConfig() {
92
+ export type Config = {
93
+ build: string;
94
+ src: string;
95
+ port: number;
96
+ secure: boolean;
97
+ esbuild?: BuildOptions;
98
+ "html-minifier-terser"?: HTMLOptions;
99
+ critical?: Options;
100
+ deletePrev?: boolean;
101
+ isCritical?: boolean;
102
+ hmr?: boolean;
103
+ handler?: string;
104
+ };
105
+ async function getBundleConfig(): Promise<Config> {
90
106
  const base = {
91
107
  build: "build",
92
108
  src: "src",
93
109
  port: 5000,
94
110
  esbuild: {},
95
111
  "html-minifier-terser": {},
96
- critical: {},
97
112
  deletePrev: true,
113
+ critical: {},
114
+ isCritical: false,
115
+ hmr: false,
116
+ secure: false,
117
+ handler: "",
98
118
  };
99
119
 
100
120
  try {
@@ -155,6 +175,7 @@ function getHMRCode(file: string, id: string, src: string) {
155
175
  }, 1000);
156
176
  });
157
177
  window.eventsource${id}.addEventListener("message", ({ data }) => {
178
+ window.lastScroll = window.scrollY;
158
179
  const dataObj = JSON.parse(data);
159
180
  const file = "${file}";
160
181
 
@@ -171,6 +192,9 @@ function getHMRCode(file: string, id: string, src: string) {
171
192
  if (dataObj.html.startsWith('<!DOCTYPE html>') || dataObj.html.startsWith('<html')) {
172
193
  document.head.remove(); // Don't try to diff the head – just re-run the scripts
173
194
  render(newHTML, document.documentElement, false);
195
+ setTimeout(() => {
196
+ window.scrollTo(0, window.lastScroll);
197
+ }, 50);
174
198
  } else {
175
199
  const hmrID = "${id}";
176
200
  const hmrElems = Array.from(newHTML.childNodes);