html-bundle 6.1.5 → 6.1.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/dist/utils.mjs CHANGED
@@ -25,8 +25,10 @@ export async function createDefaultServer(isSecure) {
25
25
  ? {
26
26
  http2: true,
27
27
  https: {
28
- key: bundleConfig.key,
29
- cert: bundleConfig.cert,
28
+ key: bundleConfig.key ||
29
+ (await readFile(path.join(process.cwd(), "localhost-key.pem"))),
30
+ cert: bundleConfig.cert ||
31
+ (await readFile(path.join(process.cwd(), "localhost.pem"))),
30
32
  },
31
33
  }
32
34
  : void 0);
@@ -78,8 +80,6 @@ async function getBundleConfig() {
78
80
  secure: false,
79
81
  handler: "",
80
82
  host: "::",
81
- key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
82
- cert: await readFile(path.join(process.cwd(), "localhost.pem")),
83
83
  };
84
84
  try {
85
85
  const cfgPath = path.resolve(process.cwd(), "bundle.config.js");
@@ -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.5",
3
+ "version": "6.1.7",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "types": "./src/config.d.ts",
@@ -32,17 +32,17 @@
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.1",
36
36
  "@web/parse5-utils": "^2.1.0",
37
37
  "await-spawn": "^4.0.2",
38
- "chokidar": "^4.0.0",
38
+ "chokidar": "^4.0.1",
39
39
  "critters": "^0.0.24",
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",
45
+ "hydro-js": "^1.5.21",
46
46
  "parse5": "^7.1.2",
47
47
  "postcss": "^8.4.47",
48
48
  "postcss-load-config": "^6.0.1"
package/src/utils.mts CHANGED
@@ -44,8 +44,12 @@ export async function createDefaultServer(isSecure: boolean) {
44
44
  ? ({
45
45
  http2: true,
46
46
  https: {
47
- key: bundleConfig.key,
48
- cert: bundleConfig.cert,
47
+ key:
48
+ bundleConfig.key ||
49
+ (await readFile(path.join(process.cwd(), "localhost-key.pem"))),
50
+ cert:
51
+ bundleConfig.cert ||
52
+ (await readFile(path.join(process.cwd(), "localhost.pem"))),
49
53
  },
50
54
  } as FastifyServerOptions)
51
55
  : void 0
@@ -104,8 +108,6 @@ async function getBundleConfig(): Promise<Config> {
104
108
  secure: false,
105
109
  handler: "",
106
110
  host: "::",
107
- key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
108
- cert: await readFile(path.join(process.cwd(), "localhost.pem")),
109
111
  };
110
112
 
111
113
  try {
@@ -166,7 +168,9 @@ function getHMRCode(file: string, id: string, src: string) {
166
168
  }, 1000);
167
169
  });
168
170
  window.eventsource${id}.addEventListener("message", ({ data }) => {
169
- window.lastScroll = window.scrollY;
171
+ if (window.lastScroll == null) {
172
+ window.lastScroll = window.scrollY;
173
+ }
170
174
  const dataObj = JSON.parse(data);
171
175
  const file = "${file}";
172
176
 
@@ -182,10 +186,14 @@ function getHMRCode(file: string, id: string, src: string) {
182
186
 
183
187
  if (dataObj.html.startsWith('<!DOCTYPE html>') || dataObj.html.startsWith('<html')) {
184
188
  document.head.remove(); // Don't try to diff the head – just re-run the scripts
185
- render(newHTML, document.documentElement, false);
186
- setTimeout(() => {
189
+
190
+ // Restore Scroll
191
+ window.addEventListener("afterRouting", () => {
187
192
  window.scrollTo(0, window.lastScroll);
188
- }, 50);
193
+ delete window.lastScroll;
194
+ }, { once: true })
195
+
196
+ render(newHTML, document.documentElement, false);
189
197
  } else {
190
198
  const hmrID = "${id}";
191
199
  const hmrElems = Array.from(newHTML.childNodes);