bun-dev-server 0.9.2 → 0.9.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 +56 -20
- package/dist/bunServeConfig.d.ts +76 -8
- package/dist/index.js +3 -4
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,33 +1,69 @@
|
|
|
1
1
|
# Bun Dev Server
|
|
2
|
+
A a dev server like Webpack dev server but only with bun, uses internal server available from [Bun.serve()](https://bun.sh/docs/api/http#bun-serve)
|
|
2
3
|
|
|
4
|
+
## Example config
|
|
3
5
|
```ts
|
|
4
6
|
//devserver.ts
|
|
5
7
|
import { startBunDevServer } from "bun-dev-server";
|
|
6
8
|
import { file } from "bun";
|
|
7
9
|
|
|
8
|
-
startBunDevServer(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
startBunDevServer(
|
|
11
|
+
{
|
|
12
|
+
buildConfig: {
|
|
13
|
+
entrypoints: ["./src/app.ts"],
|
|
14
|
+
//...
|
|
15
|
+
outdir: "dist",
|
|
16
|
+
splitting: true,
|
|
17
|
+
naming: {
|
|
18
|
+
asset: "assets/[name]-[hash].[ext]",
|
|
19
|
+
chunk: "chunks/[name]-[hash].[ext]",
|
|
20
|
+
},
|
|
17
21
|
},
|
|
22
|
+
tls: {
|
|
23
|
+
cert: file("./serve_cert.pem"),
|
|
24
|
+
key: file("./serve_key.pem"),
|
|
25
|
+
},
|
|
26
|
+
port: 44345,
|
|
27
|
+
watchDir: "./src",
|
|
28
|
+
hotReload: "plugin",
|
|
29
|
+
writeManifest: false,
|
|
30
|
+
cleanServePath: true,
|
|
31
|
+
logRequests: true,
|
|
32
|
+
reloadOnChange: true,
|
|
33
|
+
watchDelay: 2000,
|
|
18
34
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
key: file("./serve_key.pem"),
|
|
22
|
-
},
|
|
23
|
-
writeManifest: true,
|
|
24
|
-
cleanServePath: true,
|
|
25
|
-
port: 4567,
|
|
26
|
-
enableTypeScriptWatch: true,
|
|
27
|
-
watchDir: "./src",
|
|
28
|
-
});
|
|
35
|
+
import.meta
|
|
36
|
+
);
|
|
29
37
|
```
|
|
30
|
-
|
|
38
|
+
Then
|
|
31
39
|
```
|
|
32
40
|
bun run devserver.ts
|
|
33
41
|
```
|
|
42
|
+
|
|
43
|
+
# Options
|
|
44
|
+
Options that are available for configuration
|
|
45
|
+
| **Option** | **Required** | **Default** | **Description** |
|
|
46
|
+
|------------------------|--------------|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
47
|
+
| port | true | N/A | The port to run the server on. |
|
|
48
|
+
| buildConfig | true | N/A | The build configuration to use for the server. |
|
|
49
|
+
| watchDir | true | N/A | The directory to watch for changes. |
|
|
50
|
+
| watchDelay | false | 1000 | The delay in milliseconds to wait before starting a new build once a file has changed.<br> Used in debounce function, in case many changes happen in file system at once. |
|
|
51
|
+
| enableTSC | false | false | Whether to enable TypeScript checking it will use `tscConfigPath` in your project directory. |
|
|
52
|
+
| tscConfigPath | false | `./tsconfig.json` | The path to the TypeScript configuration file. |
|
|
53
|
+
| writeManifest | false | false | Whether to write the manifest file. |
|
|
54
|
+
| manifestName | false | `bun_server_manifest.json` | The name of the manifest file. |
|
|
55
|
+
| manifestWithHash | false | false | Whether to include the hash with the entrypoints in the manifest file. |
|
|
56
|
+
| hotReload | false | none | Where to place hot reload script. Available values: "plugin" | "footer" | "none" |
|
|
57
|
+
| reloadOnChange | false | false | Whether to reload the page when a file changes. <br> This requires property `hotReload` to be set to `"plugin"` or `"footer"`. |
|
|
58
|
+
| logRequests | false | false | Whether to log HTTP requests to the console. |
|
|
59
|
+
| servePath | false | `outdir` in build config or `./dist` | The path to the directory to serve files from. Takes precedence over `buildConfig.outdir`. |
|
|
60
|
+
| cleanServePath | false | false | Whether to clean the `servePath` before building a new batch. |
|
|
61
|
+
| serveOutputEjs | false | Built-in template | The EJS template used for the output of the `/` path on the server. <br> When supplying your own template, the properties that are provided during rendering are `files` and `dirs` both are arrays. |
|
|
62
|
+
| serveIndexHtmlEjs | false | Built-in template | he EJS template used for the output of the `/index.html` path on the server. <br> When supplying your own template, the property that is provided during rendering is `hashedImports` that is an array of strings. |
|
|
63
|
+
| createDefaultIndexHTML | false | true | Whether to create index.html using `serveIndexHtmlEjs` template. |
|
|
64
|
+
| beforeBuild | false | undefined | Event listener to execute before Bun builds |
|
|
65
|
+
| afterBuild | false | undefined | Event listener to execute after Bun builds |
|
|
66
|
+
| tls | false | undefined | Secure options for the server. Forwards buns `TLSOptions` |
|
|
67
|
+
| websocketPath | false | `/hmr-ws` | The websocket path to use for the server. |
|
|
68
|
+
| static | false | undefined | Static bun responses, can be used for things like `/favicon.ico` etc. |
|
|
69
|
+
|
package/dist/bunServeConfig.d.ts
CHANGED
|
@@ -9,47 +9,115 @@ export interface BuildEnv {
|
|
|
9
9
|
event: FileChangeInfo<any>;
|
|
10
10
|
}
|
|
11
11
|
export interface BunDevServerConfig extends Partial<BunServeConfig> {
|
|
12
|
+
/**
|
|
13
|
+
* The port to run the server on.
|
|
14
|
+
*/
|
|
12
15
|
port: number;
|
|
16
|
+
/**
|
|
17
|
+
* The build configuration to use for the server.
|
|
18
|
+
*/
|
|
13
19
|
buildConfig: BuildConfig;
|
|
20
|
+
/**
|
|
21
|
+
* The directory to watch for changes.
|
|
22
|
+
*/
|
|
14
23
|
watchDir: string;
|
|
15
24
|
/**
|
|
16
25
|
* The delay in milliseconds to wait before starting a new build once a file has changed.
|
|
17
|
-
* Used in debounce function, in case many changes happen in file system at once
|
|
26
|
+
* Used in debounce function, in case many changes happen in file system at once.
|
|
18
27
|
* @default 1000
|
|
19
28
|
*/
|
|
20
29
|
watchDelay?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to enable TypeScript checking it will use `tscConfigPath` in your project directory.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
21
34
|
enableTSC?: boolean;
|
|
22
35
|
/**
|
|
23
36
|
* The path to the TypeScript configuration file.
|
|
24
|
-
*
|
|
37
|
+
* @default "./tsconfig.json".
|
|
25
38
|
*/
|
|
26
39
|
tscConfigPath?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to write the manifest file.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
27
44
|
writeManifest?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The name of the manifest file.
|
|
47
|
+
* @default "bun_server_manifest.json"
|
|
48
|
+
*/
|
|
28
49
|
manifestName?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to include the hash with the entrypoints in the manifest file.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
29
54
|
manifestWithHash?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Where to place hot reload script.
|
|
57
|
+
* @default "none"
|
|
58
|
+
*/
|
|
30
59
|
hotReload?: "plugin" | "footer" | "none";
|
|
31
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Whether to reload the page when a file changes.
|
|
62
|
+
* This requires property `hotReload` to be set to `"plugin"` or `"footer"`.
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
32
65
|
reloadOnChange?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to log HTTP requests to the console.
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
logRequests?: boolean;
|
|
33
71
|
/**
|
|
34
72
|
* The path to the directory to serve files from.
|
|
35
73
|
* Takes precedence over `buildConfig.outdir`.
|
|
36
|
-
*
|
|
74
|
+
* @default `buildConfig.outdir`.
|
|
37
75
|
*/
|
|
38
76
|
servePath?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to clean the `servePath` before building a new batch.
|
|
79
|
+
*/
|
|
39
80
|
cleanServePath?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The EJS template used for the output of the `/` path on the server.
|
|
83
|
+
* When supplying your own template, the properties that are provided during rendering are `files` and `dirs` both are arrays.
|
|
84
|
+
*/
|
|
40
85
|
serveOutputEjs?: string;
|
|
41
|
-
serveOutputHtml?: string;
|
|
42
86
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
87
|
+
* The EJS template used for the output of the `/index.html` path on the server.
|
|
88
|
+
* When supplying your own template, the property that is provided during rendering is `hashedImports` that is an array of strings.
|
|
89
|
+
*/
|
|
90
|
+
serveIndexHtmlEjs?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether to create index.html using `serveIndexHtmlEjs` template.
|
|
93
|
+
* @default true.
|
|
45
94
|
*/
|
|
46
95
|
createDefaultIndexHTML?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Event listener to execute before Bun builds
|
|
98
|
+
* @param env Supplied environment for the build
|
|
99
|
+
*/
|
|
47
100
|
beforeBuild?: (env: BuildEnv) => void;
|
|
48
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Event listener to execute after Bun builds
|
|
103
|
+
* @param output The output of the build
|
|
104
|
+
* @param env Supplied environment for the build
|
|
105
|
+
*/
|
|
106
|
+
afterBuild?: (output: BuildOutput, env: BuildEnv) => void;
|
|
49
107
|
}
|
|
50
108
|
export interface BunServeConfig {
|
|
51
109
|
port: number;
|
|
110
|
+
/**
|
|
111
|
+
* Secure options for the server.
|
|
112
|
+
*/
|
|
52
113
|
tls?: TLSOptions;
|
|
114
|
+
/**
|
|
115
|
+
* The websocket path to use for the server.
|
|
116
|
+
* @default "/hmr-ws".
|
|
117
|
+
*/
|
|
53
118
|
websocketPath?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Static bun responses
|
|
121
|
+
*/
|
|
54
122
|
static?: Record<`/${string}`, Response>;
|
|
55
123
|
}
|
package/dist/index.js
CHANGED
|
@@ -926,8 +926,7 @@ var require_debounce = __commonJS((exports, module) => {
|
|
|
926
926
|
|
|
927
927
|
// src/server.ts
|
|
928
928
|
var import_ejs = __toESM(require_ejs(), 1);
|
|
929
|
-
var
|
|
930
|
-
var {$: $2 } = Bun;
|
|
929
|
+
var {$: $2 } = globalThis.Bun;
|
|
931
930
|
|
|
932
931
|
// src/serveOutputTemplate.ejs
|
|
933
932
|
var serveOutputTemplate_default = `<!DOCTYPE html>\r
|
|
@@ -1139,7 +1138,7 @@ async function startBunDevServer(serverConfig, importMeta) {
|
|
|
1139
1138
|
port: 3000,
|
|
1140
1139
|
websocketPath: DEFAULT_HMR_PATH,
|
|
1141
1140
|
serveOutputEjs: serveOutputTemplate_default,
|
|
1142
|
-
|
|
1141
|
+
serveIndexHtmlEjs: indexHTMLTemplate_default,
|
|
1143
1142
|
createDefaultIndexHTML: true,
|
|
1144
1143
|
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json")
|
|
1145
1144
|
};
|
|
@@ -1247,7 +1246,7 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
|
|
|
1247
1246
|
const output = await Bun.build(buildCfg);
|
|
1248
1247
|
publishOutputLogs(bunServer, output, event);
|
|
1249
1248
|
if (finalConfig.createDefaultIndexHTML) {
|
|
1250
|
-
publishIndexHTML(destinationPath, finalConfig.
|
|
1249
|
+
publishIndexHTML(destinationPath, finalConfig.serveIndexHtmlEjs, output, event);
|
|
1251
1250
|
}
|
|
1252
1251
|
if (finalConfig.writeManifest) {
|
|
1253
1252
|
writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
|
package/package.json
CHANGED
|
@@ -9,11 +9,14 @@
|
|
|
9
9
|
"keywords": [
|
|
10
10
|
"bun",
|
|
11
11
|
"devserver",
|
|
12
|
+
"dev server",
|
|
12
13
|
"dev",
|
|
14
|
+
"serve",
|
|
13
15
|
"server",
|
|
14
16
|
"hmr",
|
|
15
17
|
"reload",
|
|
16
|
-
"hot"
|
|
18
|
+
"hot",
|
|
19
|
+
"hot reload"
|
|
17
20
|
],
|
|
18
21
|
"files": [
|
|
19
22
|
"dist"
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
"exports": {
|
|
22
25
|
".": "./dist/index.js"
|
|
23
26
|
},
|
|
24
|
-
"version": "0.9.
|
|
27
|
+
"version": "0.9.3",
|
|
25
28
|
"module": "index.ts",
|
|
26
29
|
"type": "module",
|
|
27
30
|
"license": "MIT",
|