html-bundle 6.1.3 → 6.1.5

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
@@ -39,11 +39,6 @@ if (bundleConfig.deletePrev) {
39
39
  await rm(bundleConfig.build, { force: true, recursive: true });
40
40
  }
41
41
  async function build(files, firstRun = true) {
42
- if (isHMR && firstRun) {
43
- fastify = await createDefaultServer(isSecure);
44
- await fastify.listen({ port: bundleConfig.port, host: "::" });
45
- console.log(`💻 Server listening on http${isSecure ? "s" : ""}://localhost:${bundleConfig.port}. and is shared in the local network.`);
46
- }
47
42
  for (const file of files) {
48
43
  await createDir(file);
49
44
  if (!SUPPORTED_FILES.test(file)) {
@@ -84,11 +79,15 @@ async function build(files, firstRun = true) {
84
79
  }
85
80
  console.log(`🚀 Build finished in ${(performance.now() - timer).toFixed(2)}ms ✨`);
86
81
  if (isHMR && firstRun) {
82
+ fastify = await createDefaultServer(isSecure);
83
+ await fastify.listen({ port: bundleConfig.port, host: bundleConfig.host });
84
+ console.log(`💻 Server listening on http${isSecure ? "s" : ""}://${bundleConfig.host === "::" ? "localhost" : bundleConfig.host}:${bundleConfig.port} and is shared in the local network.`);
87
85
  console.log(`⌛ Waiting for file changes ...`);
86
+ const chokidarOptions = { awaitWriteFinish: false };
88
87
  if (postcssFile) {
89
- const postCSSWatcher = watch(postcssFile);
90
- const tailwindCSSWatcher = watch(postcssFile.replace("postcss", "tailwind")); // Assuming that the file ext is the same
91
- const tsConfigWatcher = watch(postcssFile.split("\\").slice(0, -1).join("\\") + "\\tsconfig.json");
88
+ const postCSSWatcher = watch(postcssFile, chokidarOptions);
89
+ const tailwindCSSWatcher = watch(postcssFile.replace("postcss", "tailwind"), chokidarOptions); // Assuming that the file ext is the same
90
+ const tsConfigWatcher = watch(postcssFile.split("\\").slice(0, -1).join("\\") + "\\tsconfig.json", chokidarOptions);
92
91
  const cssFiles = files.filter((file) => file.endsWith(".css"));
93
92
  postCSSWatcher.on("change", async () => await rebuildCSS(cssFiles, "postcss"));
94
93
  tailwindCSSWatcher.on("change", async () => await rebuildCSS(cssFiles, "tailwind"));
@@ -97,7 +96,7 @@ async function build(files, firstRun = true) {
97
96
  await build(files, false);
98
97
  });
99
98
  }
100
- const watcher = watch(bundleConfig.src);
99
+ const watcher = watch(bundleConfig.src, chokidarOptions);
101
100
  watcher.on("add", async (file) => {
102
101
  file = String.raw `${file}`.replace(/\\/g, "/"); // glob and chokidar diff
103
102
  if (files.includes(file) || INLINE_BUNDLE_FILE.test(file)) {
package/dist/utils.mjs CHANGED
@@ -25,8 +25,8 @@ export async function createDefaultServer(isSecure) {
25
25
  ? {
26
26
  http2: true,
27
27
  https: {
28
- key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
29
- cert: await readFile(path.join(process.cwd(), "localhost.pem")),
28
+ key: bundleConfig.key,
29
+ cert: bundleConfig.cert,
30
30
  },
31
31
  }
32
32
  : void 0);
@@ -77,6 +77,9 @@ async function getBundleConfig() {
77
77
  hmr: false,
78
78
  secure: false,
79
79
  handler: "",
80
+ host: "::",
81
+ key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
82
+ cert: await readFile(path.join(process.cwd(), "localhost.pem")),
80
83
  };
81
84
  try {
82
85
  const cfgPath = path.resolve(process.cwd(), "bundle.config.js");
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "html-bundle",
3
- "version": "6.1.3",
4
- "description": "A very simple bundler for HTML SFC",
5
- "bin": "./dist/bundle.mjs",
6
- "types": "./src/config.d.ts",
7
- "scripts": {
8
- "start": "tsc",
9
- "update": "npx npm-check-updates -u && npx typesync && npm i && npm outdated"
10
- },
11
- "keywords": [
12
- "bundler",
13
- "SFC",
14
- "HTML",
15
- "TypeScript",
16
- "esbuild",
17
- "hydro-js"
18
- ],
19
- "author": "Fabian Klingenberg <klingenberg.fabian@gmx.de> (https://klingenberg.netlify.app/)",
20
- "license": "MIT",
21
- "devDependencies": {
22
- "@types/cssnano": "^5.1.0",
23
- "@types/glob": "^8.1.0",
24
- "@types/html-minifier-terser": "^7.0.2",
25
- "@types/parse5": "^7.0.0",
26
- "@types/postcss-load-config": "^3.0.1",
27
- "typescript": "^5.5.4"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "git+https://github.com/Krutsch/html-bundle.git"
32
- },
33
- "bugs": "https://github.com/Krutsch/html-bundle/issues",
34
- "dependencies": {
35
- "@fastify/static": "^7.0.4",
36
- "@web/parse5-utils": "^2.1.0",
37
- "await-spawn": "^4.0.2",
38
- "chokidar": "^3.6.0",
39
- "critters": "^0.0.24",
40
- "cssnano": "^7.0.4",
41
- "esbuild": "^0.23.0",
42
- "fastify": "^4.28.1",
43
- "glob": "^11.0.0",
44
- "html-minifier-terser": "^7.2.0",
45
- "hydro-js": "^1.5.19",
46
- "parse5": "^7.1.2",
47
- "postcss": "^8.4.41",
48
- "postcss-load-config": "^6.0.1"
49
- }
50
- }
1
+ {
2
+ "name": "html-bundle",
3
+ "version": "6.1.5",
4
+ "description": "A very simple bundler for HTML SFC",
5
+ "bin": "./dist/bundle.mjs",
6
+ "types": "./src/config.d.ts",
7
+ "scripts": {
8
+ "start": "tsc",
9
+ "update": "npx npm-check-updates -u && npx typesync && npm i && npm outdated"
10
+ },
11
+ "keywords": [
12
+ "bundler",
13
+ "SFC",
14
+ "HTML",
15
+ "TypeScript",
16
+ "esbuild",
17
+ "hydro-js"
18
+ ],
19
+ "author": "Fabian Klingenberg <klingenberg.fabian@gmx.de> (https://klingenberg.netlify.app/)",
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@types/cssnano": "^5.1.0",
23
+ "@types/glob": "^8.1.0",
24
+ "@types/html-minifier-terser": "^7.0.2",
25
+ "@types/parse5": "^7.0.0",
26
+ "@types/postcss-load-config": "^3.0.1",
27
+ "typescript": "^5.6.2"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/Krutsch/html-bundle.git"
32
+ },
33
+ "bugs": "https://github.com/Krutsch/html-bundle/issues",
34
+ "dependencies": {
35
+ "@fastify/static": "^8.0.0",
36
+ "@web/parse5-utils": "^2.1.0",
37
+ "await-spawn": "^4.0.2",
38
+ "chokidar": "^4.0.0",
39
+ "critters": "^0.0.24",
40
+ "cssnano": "^7.0.6",
41
+ "esbuild": "^0.23.1",
42
+ "fastify": "^5.0.0",
43
+ "glob": "^11.0.0",
44
+ "html-minifier-terser": "^7.2.0",
45
+ "hydro-js": "^1.5.19",
46
+ "parse5": "^7.1.2",
47
+ "postcss": "^8.4.47",
48
+ "postcss-load-config": "^6.0.1"
49
+ }
50
+ }
package/src/bundle.mts CHANGED
@@ -56,16 +56,6 @@ if (bundleConfig.deletePrev) {
56
56
  }
57
57
 
58
58
  async function build(files: string[], firstRun = true) {
59
- if (isHMR && firstRun) {
60
- fastify = await createDefaultServer(isSecure);
61
- await fastify.listen({ port: bundleConfig.port, host: "::" });
62
- console.log(
63
- `💻 Server listening on http${isSecure ? "s" : ""}://localhost:${
64
- bundleConfig.port
65
- }. and is shared in the local network.`
66
- );
67
- }
68
-
69
59
  for (const file of files) {
70
60
  await createDir(file);
71
61
 
@@ -106,15 +96,26 @@ async function build(files: string[], firstRun = true) {
106
96
  );
107
97
 
108
98
  if (isHMR && firstRun) {
99
+ fastify = await createDefaultServer(isSecure);
100
+ await fastify.listen({ port: bundleConfig.port, host: bundleConfig.host });
101
+ console.log(
102
+ `💻 Server listening on http${isSecure ? "s" : ""}://${
103
+ bundleConfig.host === "::" ? "localhost" : bundleConfig.host
104
+ }:${bundleConfig.port} and is shared in the local network.`
105
+ );
106
+
109
107
  console.log(`⌛ Waiting for file changes ...`);
110
108
 
109
+ const chokidarOptions = { awaitWriteFinish: false };
111
110
  if (postcssFile) {
112
- const postCSSWatcher = watch(postcssFile);
111
+ const postCSSWatcher = watch(postcssFile, chokidarOptions);
113
112
  const tailwindCSSWatcher = watch(
114
- postcssFile.replace("postcss", "tailwind")
113
+ postcssFile.replace("postcss", "tailwind"),
114
+ chokidarOptions
115
115
  ); // Assuming that the file ext is the same
116
116
  const tsConfigWatcher = watch(
117
- postcssFile.split("\\").slice(0, -1).join("\\") + "\\tsconfig.json"
117
+ postcssFile.split("\\").slice(0, -1).join("\\") + "\\tsconfig.json",
118
+ chokidarOptions
118
119
  );
119
120
 
120
121
  const cssFiles = files.filter((file) => file.endsWith(".css"));
@@ -132,7 +133,7 @@ async function build(files: string[], firstRun = true) {
132
133
  });
133
134
  }
134
135
 
135
- const watcher = watch(bundleConfig.src);
136
+ const watcher = watch(bundleConfig.src, chokidarOptions);
136
137
  watcher.on("add", async (file) => {
137
138
  file = String.raw`${file}`.replace(/\\/g, "/"); // glob and chokidar diff
138
139
  if (files.includes(file) || INLINE_BUNDLE_FILE.test(file)) {
package/src/config.d.ts CHANGED
@@ -10,4 +10,7 @@ export type Config = {
10
10
  isCritical?: boolean;
11
11
  hmr?: boolean;
12
12
  handler?: string;
13
+ host?: string;
14
+ key?: Buffer;
15
+ cert?: Buffer;
13
16
  };
package/src/utils.mts CHANGED
@@ -44,8 +44,8 @@ export async function createDefaultServer(isSecure: boolean) {
44
44
  ? ({
45
45
  http2: true,
46
46
  https: {
47
- key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
48
- cert: await readFile(path.join(process.cwd(), "localhost.pem")),
47
+ key: bundleConfig.key,
48
+ cert: bundleConfig.cert,
49
49
  },
50
50
  } as FastifyServerOptions)
51
51
  : void 0
@@ -103,6 +103,9 @@ async function getBundleConfig(): Promise<Config> {
103
103
  hmr: false,
104
104
  secure: false,
105
105
  handler: "",
106
+ host: "::",
107
+ key: await readFile(path.join(process.cwd(), "localhost-key.pem")),
108
+ cert: await readFile(path.join(process.cwd(), "localhost.pem")),
106
109
  };
107
110
 
108
111
  try {