bun-dev-server 0.1.0 → 0.3.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/README.md +23 -22
- package/bunHmrPlugin.ts +8 -3
- package/bunManifest.ts +9 -9
- package/bunServeConfig.ts +1 -0
- package/index.ts +2 -2
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
# Bun Dev Server
|
|
2
2
|
|
|
3
|
-
```
|
|
3
|
+
```ts
|
|
4
4
|
//devserver.ts
|
|
5
|
-
import {startBunDevServer} from "bun-dev-server"
|
|
6
|
-
import { file } from "bun"
|
|
5
|
+
import { startBunDevServer } from "bun-dev-server";
|
|
6
|
+
import { file } from "bun";
|
|
7
7
|
|
|
8
8
|
startBunDevServer({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
tls: {
|
|
19
|
-
cert: file("./serve_cert.pem"),
|
|
20
|
-
key: file("./serve_key.pem"),
|
|
9
|
+
buildConfig: {
|
|
10
|
+
entrypoints: ["./src/app.ts"],
|
|
11
|
+
//...
|
|
12
|
+
outdir: "dist",
|
|
13
|
+
splitting: true,
|
|
14
|
+
naming: {
|
|
15
|
+
asset: "assets/[name]-[hash].[ext]",
|
|
16
|
+
chunk: "chunks/[name]-[hash].[ext]",
|
|
21
17
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
},
|
|
19
|
+
tls: {
|
|
20
|
+
cert: file("./serve_cert.pem"),
|
|
21
|
+
key: file("./serve_key.pem"),
|
|
22
|
+
},
|
|
23
|
+
writeManifest: true,
|
|
24
|
+
cleanServePath: true,
|
|
25
|
+
port: 4567,
|
|
26
|
+
enableTypeScriptWatch: true,
|
|
27
|
+
watchDir: "./src",
|
|
28
|
+
});
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
```
|
|
31
32
|
bun run devserver.ts
|
|
32
|
-
```
|
|
33
|
+
```
|
package/bunHmrPlugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BunPlugin, Loader } from "bun";
|
|
2
2
|
import { bunHotReload } from "./bunClientHmr";
|
|
3
3
|
import { readFile } from "fs/promises";
|
|
4
4
|
import { type BunDevServerSocketConfig } from "./bunServeConfig";
|
|
@@ -10,11 +10,16 @@ export function getBunHMRPlugin(config: BunDevServerSocketConfig) {
|
|
|
10
10
|
let hmrAdded = false;
|
|
11
11
|
build.onLoad({ filter: /\.m?tsx?/ }, async (args) => {
|
|
12
12
|
const contents = await readFile(args.path, { encoding: "utf-8" });
|
|
13
|
+
const isTSx = /\.m?tsx$/.test(args.path);
|
|
14
|
+
const isJSx = /\.m?jsx$/.test(args.path);
|
|
15
|
+
const isJS = /\.m?js$/.test(args.path);
|
|
16
|
+
const isTS = /\.m?ts$/.test(args.path);
|
|
17
|
+
const loader: Loader = isTSx ? "tsx" : isJSx ? "jsx" : isTS ? "ts" : isJS ? "js" : "text";
|
|
13
18
|
if (!hmrAdded) {
|
|
14
19
|
hmrAdded = true;
|
|
15
|
-
return { contents: `import "bun-hot-reload"\n` + contents, loader
|
|
20
|
+
return { contents: `import "bun-hot-reload"\n` + contents, loader };
|
|
16
21
|
}
|
|
17
|
-
return { contents, loader
|
|
22
|
+
return { contents, loader };
|
|
18
23
|
});
|
|
19
24
|
build.onLoad({ filter: /./, namespace: "bun-hot-reload" }, async (args) => {
|
|
20
25
|
|
package/bunManifest.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { type BuildOutput, write, pathToFileURL } from "bun";
|
|
2
|
-
export function writeManifest(output: BuildOutput, outdir: string, manifestName = "
|
|
2
|
+
export function writeManifest(output: BuildOutput, outdir: string, withHash = false, manifestName = "bunmanifest.txt") {
|
|
3
3
|
const entryPoints = output.outputs.filter(o => o.kind === "entry-point");
|
|
4
|
-
const epTable = [];
|
|
4
|
+
const epTable: string[] = [];
|
|
5
5
|
for (const ep of entryPoints) {
|
|
6
6
|
const basePathUrl = pathToFileURL(outdir);
|
|
7
7
|
const epUrl = pathToFileURL(ep.path);
|
|
8
8
|
const relativePath = epUrl.href.replace(`${basePathUrl.href}/`, "");
|
|
9
|
-
const nameNoJs = relativePath.replace(".js", "");
|
|
10
|
-
const hashedImport = `${relativePath}
|
|
11
|
-
epTable.push(
|
|
12
|
-
}
|
|
13
|
-
const outObj = {};
|
|
14
|
-
for (const element of epTable) {
|
|
15
|
-
Object.assign(outObj, { [element.name]: { js: [`${element.path}`] } });
|
|
9
|
+
// const nameNoJs = relativePath.replace(".js", "");
|
|
10
|
+
const hashedImport = `${relativePath}${withHash ? `?${ep.hash}` : ``}`;
|
|
11
|
+
epTable.push(hashedImport);
|
|
16
12
|
}
|
|
13
|
+
const outObj = { js: epTable };
|
|
14
|
+
// for (const element of epTable) {
|
|
15
|
+
// Object.assign(outObj, { [element.name]: { js: [`${element.path}`] } });
|
|
16
|
+
// }
|
|
17
17
|
write(`${outdir}/${manifestName}`, JSON.stringify(outObj));
|
|
18
18
|
}
|
package/bunServeConfig.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface BunDevServerConfig extends Partial<BunDevServerSocketConfig> {
|
|
|
7
7
|
enableTypeScriptWatch?: boolean;
|
|
8
8
|
writeManifest?: boolean;
|
|
9
9
|
manifestName?: string;
|
|
10
|
+
manifestWithHash?: boolean;
|
|
10
11
|
reloadOnChange?: boolean;
|
|
11
12
|
/**
|
|
12
13
|
* The path to the directory to serve files from.
|
package/index.ts
CHANGED
|
@@ -151,7 +151,7 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
|
|
|
151
151
|
publishOutputLogs(output, { filename: "Initial", eventType: "change" });
|
|
152
152
|
publishIndexHTML(output, { filename: "Initial", eventType: "change" });
|
|
153
153
|
if (finalConfig.writeManifest) {
|
|
154
|
-
writeManifest(output, dst, finalConfig.manifestName);
|
|
154
|
+
writeManifest(output, dst, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
155
155
|
}
|
|
156
156
|
// $`tsc --watch`.then((tsc) => {
|
|
157
157
|
// console.log("ASDASD");
|
|
@@ -173,7 +173,7 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
|
|
|
173
173
|
publishOutputLogs(output, event);
|
|
174
174
|
publishIndexHTML(output, event);
|
|
175
175
|
if (finalConfig.writeManifest) {
|
|
176
|
-
writeManifest(output, dst, finalConfig.manifestName);
|
|
176
|
+
writeManifest(output, dst, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
177
177
|
}
|
|
178
178
|
if (finalConfig.reloadOnChange) {
|
|
179
179
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
package/package.json
CHANGED
|
@@ -6,7 +6,14 @@
|
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SPWizard01/bun-dev-server"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
9
|
+
"keywords": [
|
|
10
|
+
"bun",
|
|
11
|
+
"devserver",
|
|
12
|
+
"hmr",
|
|
13
|
+
"reload",
|
|
14
|
+
"hot"
|
|
15
|
+
],
|
|
16
|
+
"version": "0.3.0",
|
|
10
17
|
"module": "index.ts",
|
|
11
18
|
"type": "module",
|
|
12
19
|
"license": "MIT",
|
|
@@ -17,7 +24,7 @@
|
|
|
17
24
|
"@types/bun": "latest"
|
|
18
25
|
},
|
|
19
26
|
"peerDependencies": {
|
|
20
|
-
"typescript": "^5.
|
|
27
|
+
"typescript": "^5.7.2"
|
|
21
28
|
},
|
|
22
29
|
"dependencies": {
|
|
23
30
|
"ejs": "^3.1.10",
|