html-bundle 6.0.0 → 6.0.3
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 +4 -8
- package/dist/bundle.mjs +4 -5
- package/dist/utils.mjs +23 -2
- package/example.gif +0 -0
- package/package.json +3 -3
- package/src/bundle.mts +5 -5
- package/src/utils.mts +23 -2
- package/output.JPG +0 -0
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
|
+

|
|
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
|
-

|
|
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
|
-

|
package/dist/bundle.mjs
CHANGED
|
@@ -32,7 +32,7 @@ const execFilePromise = promisify(execFile);
|
|
|
32
32
|
if (bundleConfig.deletePrev) {
|
|
33
33
|
await rm(bundleConfig.build, { force: true, recursive: true });
|
|
34
34
|
}
|
|
35
|
-
glob(`${bundleConfig.src}
|
|
35
|
+
glob(`${bundleConfig.src}/**/*`, build);
|
|
36
36
|
async function build(err, files, firstRun = true) {
|
|
37
37
|
if (err) {
|
|
38
38
|
console.error(err);
|
|
@@ -95,12 +95,11 @@ async function build(err, files, firstRun = true) {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
const watcher = watch(bundleConfig.src);
|
|
98
|
-
let addCount = 0; // The add watcher will add all the files initially - do not rebuild them
|
|
99
98
|
watcher.on("add", async (file) => {
|
|
100
|
-
|
|
99
|
+
file = String.raw `${file}`.replace(/\\/g, "/"); // glob and chokidar diff
|
|
100
|
+
if (files.includes(file) || INLINE_BUNDLE_FILE.test(file)) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
file = String.raw `${file}`.replace(/\\/g, "/"); // glob and chokidar diff
|
|
104
103
|
await rebuild(file);
|
|
105
104
|
console.log(`⚡ added ${file} to the build`);
|
|
106
105
|
});
|
|
@@ -205,11 +204,11 @@ async function minifyCode() {
|
|
|
205
204
|
missingPkg = true;
|
|
206
205
|
const packageNameRegex = /(?<=").*(?=")/;
|
|
207
206
|
const [pkgName] = error.text.match(packageNameRegex);
|
|
208
|
-
console.log(`📦 Package ${pkgName} was installed for you`);
|
|
209
207
|
await awaitSpawn(process.platform === "win32" ? "npm.cmd" : "npm", [
|
|
210
208
|
"install",
|
|
211
209
|
pkgName,
|
|
212
210
|
]);
|
|
211
|
+
console.log(`📦 Package ${pkgName} was installed for you`);
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
if (missingPkg) {
|
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,35 @@ 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
|
|
|
160
167
|
if (dataObj.file === \`${src}/index.html\`) {
|
|
161
168
|
dispatchEvent(new Event("popstate"));
|
|
162
169
|
}
|
|
163
170
|
} else if (dataObj.file.endsWith(".css")) {
|
|
164
|
-
|
|
171
|
+
const now = performance.now();
|
|
172
|
+
if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
|
|
173
|
+
$$('link[rel="stylesheet"][href]').forEach(link => {
|
|
174
|
+
link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
|
|
175
|
+
})
|
|
176
|
+
window.lastCalled.set(dataObj.file, now)
|
|
177
|
+
}
|
|
165
178
|
} else if (dataObj.file.endsWith(".js")) {
|
|
166
|
-
|
|
179
|
+
const now = performance.now();
|
|
180
|
+
if (!window.lastCalled.has(dataObj.file) || now - window.lastCalled.get(dataObj.file) > 100) {
|
|
181
|
+
$$('link[rel="stylesheet"][href]').forEach(link => {
|
|
182
|
+
link.setAttribute("href", link.getAttribute("href") + "?v=" + String(Math.random().toFixed(4)).slice(2));
|
|
183
|
+
})
|
|
184
|
+
updateElem("script");
|
|
185
|
+
window.lastCalled.set(dataObj.file, now)
|
|
186
|
+
}
|
|
167
187
|
}
|
|
188
|
+
|
|
168
189
|
|
|
169
190
|
function updateElem(type) {
|
|
170
191
|
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.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "A very simple bundler for HTML SFC",
|
|
5
5
|
"bin": "./dist/bundle.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"chokidar": "^3.5.2",
|
|
37
37
|
"critical": "^4.0.1",
|
|
38
38
|
"cssnano": "^5.0.14",
|
|
39
|
-
"esbuild": "^0.14.
|
|
40
|
-
"fastify": "^3.25.
|
|
39
|
+
"esbuild": "^0.14.9",
|
|
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",
|
package/src/bundle.mts
CHANGED
|
@@ -48,7 +48,7 @@ if (bundleConfig.deletePrev) {
|
|
|
48
48
|
await rm(bundleConfig.build, { force: true, recursive: true });
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
glob(`${bundleConfig.src}
|
|
51
|
+
glob(`${bundleConfig.src}/**/*`, build);
|
|
52
52
|
|
|
53
53
|
async function build(err: any, files: string[], firstRun = true) {
|
|
54
54
|
if (err) {
|
|
@@ -127,12 +127,11 @@ async function build(err: any, files: string[], firstRun = true) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const watcher = watch(bundleConfig.src);
|
|
130
|
-
let addCount = 0; // The add watcher will add all the files initially - do not rebuild them
|
|
131
130
|
watcher.on("add", async (file) => {
|
|
132
|
-
|
|
131
|
+
file = String.raw`${file}`.replace(/\\/g, "/"); // glob and chokidar diff
|
|
132
|
+
if (files.includes(file) || INLINE_BUNDLE_FILE.test(file)) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
file = String.raw`${file}`.replace(/\\/g, "/"); // glob and chokidar diff
|
|
136
135
|
|
|
137
136
|
await rebuild(file);
|
|
138
137
|
|
|
@@ -244,12 +243,13 @@ async function minifyCode(): Promise<unknown> {
|
|
|
244
243
|
missingPkg = true;
|
|
245
244
|
const packageNameRegex = /(?<=").*(?=")/;
|
|
246
245
|
const [pkgName] = error.text.match(packageNameRegex);
|
|
247
|
-
console.log(`📦 Package ${pkgName} was installed for you`);
|
|
248
246
|
|
|
249
247
|
await awaitSpawn(process.platform === "win32" ? "npm.cmd" : "npm", [
|
|
250
248
|
"install",
|
|
251
249
|
pkgName,
|
|
252
250
|
]);
|
|
251
|
+
|
|
252
|
+
console.log(`📦 Package ${pkgName} was installed for you`);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
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
|
-
|
|
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
|
-
|
|
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
|