html-bundle 5.4.18 → 5.5.0
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.js +625 -0
- package/package.json +14 -14
- package/src/bundle.ts +33 -21
- package/tsconfig.json +1 -1
- package/cjs/bundle.js +0 -695
- package/esm/bundle.js +0 -636
- package/tsconfig.cjs.json +0 -16
package/src/bundle.ts
CHANGED
|
@@ -49,7 +49,8 @@ if (isServeOnly) {
|
|
|
49
49
|
// Performance Observer and file watcher
|
|
50
50
|
const globHTML = new Event.EventEmitter();
|
|
51
51
|
const taskEmitter = new Event.EventEmitter();
|
|
52
|
-
|
|
52
|
+
let start = performance.now();
|
|
53
|
+
let addedHMR = false;
|
|
53
54
|
let expectedTasks = 0; // This will be increased in globHandlers
|
|
54
55
|
let finishedTasks = 0; // Current status
|
|
55
56
|
taskEmitter.on("done", () => {
|
|
@@ -60,26 +61,13 @@ if (isServeOnly) {
|
|
|
60
61
|
`🚀 Build finished in ${(performance.now() - start).toFixed(2)}ms ✨`
|
|
61
62
|
);
|
|
62
63
|
|
|
63
|
-
if (isHMR) {
|
|
64
|
+
if (isHMR && !addedHMR) {
|
|
65
|
+
addedHMR = true;
|
|
64
66
|
if (file) {
|
|
65
67
|
const postCSSWatcher = watch(file);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
plugins = newConfig.plugins;
|
|
70
|
-
options = newConfig.options;
|
|
71
|
-
CSSprocessor = postcss(plugins as AcceptedPlugin[]);
|
|
72
|
-
|
|
73
|
-
glob(`${SOURCE_FOLDER}/**/*.css`, {}, (err, files) => {
|
|
74
|
-
errorHandler(err);
|
|
75
|
-
expectedTasks += files.length;
|
|
76
|
-
for (const filename of files) {
|
|
77
|
-
const [buildFilename, buildPathDir] = getBuildNames(filename);
|
|
78
|
-
fs.mkdirSync(buildPathDir, { recursive: true });
|
|
79
|
-
minifyCSS(filename, buildFilename);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
68
|
+
const tailwindCSSWatcher = watch(file.replace("postcss", "tailwind"));
|
|
69
|
+
postCSSWatcher.on("change", () => rebuildCSS("postcss"));
|
|
70
|
+
tailwindCSSWatcher.on("change", () => rebuildCSS("tailwind"));
|
|
83
71
|
}
|
|
84
72
|
|
|
85
73
|
console.log(`⌛ Waiting for file changes ...`);
|
|
@@ -89,6 +77,8 @@ if (isServeOnly) {
|
|
|
89
77
|
let hasJSTS = false;
|
|
90
78
|
|
|
91
79
|
watcher.on("add", (filename) => {
|
|
80
|
+
start = performance.now();
|
|
81
|
+
rebuildCSS();
|
|
92
82
|
// Return if it was added by the build system itself
|
|
93
83
|
if (/-bundle-\d+\.(j|t)sx?$/.test(filename)) {
|
|
94
84
|
return;
|
|
@@ -112,6 +102,8 @@ if (isServeOnly) {
|
|
|
112
102
|
});
|
|
113
103
|
});
|
|
114
104
|
watcher.on("change", (filename) => {
|
|
105
|
+
start = performance.now();
|
|
106
|
+
rebuildCSS();
|
|
115
107
|
// Return if it was changed by the build system itself
|
|
116
108
|
if (/-bundle-\d+\.(j|t)sx?$/.test(filename)) {
|
|
117
109
|
return;
|
|
@@ -123,6 +115,7 @@ if (isServeOnly) {
|
|
|
123
115
|
console.log(`⚡ modified ${buildFilename}`);
|
|
124
116
|
});
|
|
125
117
|
watcher.on("unlink", (filename) => {
|
|
118
|
+
start = performance.now();
|
|
126
119
|
// Return if it was deleted by the build system itself
|
|
127
120
|
if (/-bundle-\d+\.(j|t)sx?$/.test(filename)) {
|
|
128
121
|
return;
|
|
@@ -143,6 +136,25 @@ if (isServeOnly) {
|
|
|
143
136
|
}
|
|
144
137
|
});
|
|
145
138
|
|
|
139
|
+
function rebuildCSS(config?: string) {
|
|
140
|
+
start = performance.now();
|
|
141
|
+
if (config)
|
|
142
|
+
console.log(`⚡ modified ${config}.config – CSS will rebuild now.`);
|
|
143
|
+
const newConfig = createPostCSSConfig();
|
|
144
|
+
plugins = newConfig.plugins;
|
|
145
|
+
options = newConfig.options;
|
|
146
|
+
CSSprocessor = postcss(plugins as AcceptedPlugin[]);
|
|
147
|
+
glob(`${SOURCE_FOLDER}/**/*.css`, {}, (err, files) => {
|
|
148
|
+
errorHandler(err);
|
|
149
|
+
expectedTasks += files.length;
|
|
150
|
+
for (const filename of files) {
|
|
151
|
+
const [buildFilename, buildPathDir] = getBuildNames(filename);
|
|
152
|
+
fs.mkdirSync(buildPathDir, { recursive: true });
|
|
153
|
+
minifyCSS(filename, buildFilename);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
146
158
|
// Basic configuration
|
|
147
159
|
const SOURCE_FOLDER = "src";
|
|
148
160
|
const BUILD_FOLDER = "build";
|
|
@@ -318,8 +330,8 @@ if (isServeOnly) {
|
|
|
318
330
|
taskEmitter.emit("done");
|
|
319
331
|
globHTML.emit("getReady");
|
|
320
332
|
|
|
321
|
-
if (serverSentEvents) {
|
|
322
|
-
const changedFile = tsMaybeX2JS(file
|
|
333
|
+
if (serverSentEvents && file) {
|
|
334
|
+
const changedFile = tsMaybeX2JS(file);
|
|
323
335
|
const [buildFilename] = getBuildNames(changedFile);
|
|
324
336
|
const js = fs.readFileSync(buildFilename, { encoding: "utf8" });
|
|
325
337
|
serverSentEvents({
|