html-bundle 6.0.1 → 6.0.2

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
@@ -16,6 +16,10 @@ A (primarily) zero-config bundler for HTML files. The idea is to use HTML as Sin
16
16
  - 🚋 Watcher on PostCSS and Tailwind CSS and TS Config
17
17
  - 🛡️ Almost no need to restart
18
18
 
19
+ ## Demo
20
+
21
+ ![Demo](./example.gif)
22
+
19
23
  ## Installation and Usage
20
24
 
21
25
  ```properties
@@ -100,10 +104,6 @@ Set `"jsxFactory": "h"` in `tsconfig.json` for JSX.
100
104
  </html>
101
105
  ```
102
106
 
103
- ### Output
104
-
105
- ![Output](output.JPG)
106
-
107
107
  ## Example Vue.js@next
108
108
 
109
109
  Set `"jsxFactory": "h"` in `tsconfig.json`.
@@ -173,7 +173,3 @@ Set `"jsxFactory": "h"` in `tsconfig.json`.
173
173
  </body>
174
174
  </html>
175
175
  ```
176
-
177
- ### Demo
178
-
179
- ![Demo](./example.gif)
package/dist/utils.mjs CHANGED
@@ -109,6 +109,7 @@ function randomText() {
109
109
  function getHMRCode(file, id, src) {
110
110
  return `import { render, html, $, $$, setShouldSetReactivity } from "hydro-js";
111
111
  window.isHMR = true;
112
+ window.lastCalled = new Map();
112
113
  if (!window.eventsource${id}) {
113
114
  window.eventsource${id} = new EventSource("/hmr");
114
115
  window.eventsource${id}.addEventListener('error', (e) => {
@@ -156,15 +157,37 @@ function getHMRCode(file, id, src) {
156
157
  }
157
158
  }
158
159
  }
160
+
161
+ $$('link[rel="stylesheet"][href]').forEach(link => {
162
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
163
+ })
164
+ if (dataObj.html.includes("<script")) updateElem("script");
165
+
159
166
 
167
+ console.log("dispatch")
168
+ console.log(dataObj.file)
160
169
  if (dataObj.file === \`${src}/index.html\`) {
161
170
  dispatchEvent(new Event("popstate"));
162
171
  }
163
172
  } else if (dataObj.file.endsWith(".css")) {
164
- updateElem("link");
173
+ const now = performance.now();
174
+ if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
175
+ $$('link[rel="stylesheet"][href]').forEach(link => {
176
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
177
+ })
178
+ window.lastCalled.set(dataObj.file, now)
179
+ }
165
180
  } else if (dataObj.file.endsWith(".js")) {
166
- updateElem("script")
181
+ const now = performance.now();
182
+ if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
183
+ $$('link[rel="stylesheet"][href]').forEach(link => {
184
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
185
+ })
186
+ updateElem("script");
187
+ window.lastCalled.set(dataObj.file, now)
188
+ }
167
189
  }
190
+
168
191
 
169
192
  function updateElem(type) {
170
193
  const hmrId = "${id}";
package/example.gif CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-bundle",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "A very simple bundler for HTML SFC",
5
5
  "bin": "./dist/bundle.mjs",
6
6
  "scripts": {
package/src/utils.mts CHANGED
@@ -145,6 +145,7 @@ function randomText() {
145
145
  function getHMRCode(file: string, id: string, src: string) {
146
146
  return `import { render, html, $, $$, setShouldSetReactivity } from "hydro-js";
147
147
  window.isHMR = true;
148
+ window.lastCalled = new Map();
148
149
  if (!window.eventsource${id}) {
149
150
  window.eventsource${id} = new EventSource("/hmr");
150
151
  window.eventsource${id}.addEventListener('error', (e) => {
@@ -192,15 +193,35 @@ function getHMRCode(file: string, id: string, src: string) {
192
193
  }
193
194
  }
194
195
  }
196
+
197
+ $$('link[rel="stylesheet"][href]').forEach(link => {
198
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
199
+ })
200
+ if (dataObj.html.includes("<script")) updateElem("script");
201
+
195
202
 
196
203
  if (dataObj.file === \`${src}/index.html\`) {
197
204
  dispatchEvent(new Event("popstate"));
198
205
  }
199
206
  } else if (dataObj.file.endsWith(".css")) {
200
- updateElem("link");
207
+ const now = performance.now();
208
+ if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
209
+ $$('link[rel="stylesheet"][href]').forEach(link => {
210
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
211
+ })
212
+ window.lastCalled.set(dataObj.file, now)
213
+ }
201
214
  } else if (dataObj.file.endsWith(".js")) {
202
- updateElem("script")
215
+ const now = performance.now();
216
+ if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
217
+ $$('link[rel="stylesheet"][href]').forEach(link => {
218
+ link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
219
+ })
220
+ updateElem("script");
221
+ window.lastCalled.set(dataObj.file, now)
222
+ }
203
223
  }
224
+
204
225
 
205
226
  function updateElem(type) {
206
227
  const hmrId = "${id}";
package/output.JPG DELETED
Binary file