@t8/serve 0.1.19 → 0.1.20
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 -4
- package/dist/index.js +3 -2
- package/dist/run.cjs +3 -2
- package/dist/run.mjs +3 -2
- package/package.json +1 -1
- package/src/BundleConfig.ts +16 -0
- package/src/Config.ts +30 -1
- package/src/bundle.ts +3 -2
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npx @t8/serve 3000 app public dist -b src/index.ts
|
|
|
32
32
|
/playground
|
|
33
33
|
- index.css
|
|
34
34
|
- index.html
|
|
35
|
-
|
|
35
|
+
+ <script src="/dist/index.js"></script>
|
|
36
36
|
- index.ts
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -63,8 +63,8 @@ import { serve } from "@t8/serve";
|
|
|
63
63
|
let server = await serve({
|
|
64
64
|
port: 3000,
|
|
65
65
|
path: "app",
|
|
66
|
+
bundle: true, // or `{ input, output }`, or `input` path
|
|
66
67
|
spa: true,
|
|
67
|
-
bundle: true,
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
// Stop
|
|
@@ -78,7 +78,7 @@ server.close();
|
|
|
78
78
|
/playground
|
|
79
79
|
- index.css
|
|
80
80
|
- index.html
|
|
81
|
-
|
|
81
|
+
+ <script src="/dist/index.js"></script>
|
|
82
82
|
- index.ts
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -92,8 +92,8 @@ let server: Server;
|
|
|
92
92
|
test.beforeAll(async () => {
|
|
93
93
|
server = await serve({
|
|
94
94
|
path: "playground",
|
|
95
|
+
bundle: "src/index.tsx",
|
|
95
96
|
spa: true,
|
|
96
|
-
bundle: true,
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
|
package/dist/index.js
CHANGED
|
@@ -16,9 +16,10 @@ async function bundle({ path = "", bundle: options } = {}) {
|
|
|
16
16
|
input: options
|
|
17
17
|
};
|
|
18
18
|
else normalizedOptions = options;
|
|
19
|
+
let dir = normalizedOptions.dir ?? "dist";
|
|
19
20
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
20
|
-
let outputFile = join(path,
|
|
21
|
-
await rm(join(path,
|
|
21
|
+
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
22
|
+
await rm(join(path, dir), { recursive: true, force: true });
|
|
22
23
|
await build({
|
|
23
24
|
entryPoints: [inputFile],
|
|
24
25
|
outfile: outputFile,
|
package/dist/run.cjs
CHANGED
|
@@ -19,9 +19,10 @@ async function bundle({ path = "", bundle: options } = {}) {
|
|
|
19
19
|
input: options
|
|
20
20
|
};
|
|
21
21
|
else normalizedOptions = options;
|
|
22
|
+
let dir = normalizedOptions.dir ?? "dist";
|
|
22
23
|
let inputFile = (0, import_node_path.join)(path, normalizedOptions.input ?? "index.ts");
|
|
23
|
-
let outputFile = (0, import_node_path.join)(path,
|
|
24
|
-
await (0, import_promises.rm)((0, import_node_path.join)(path,
|
|
24
|
+
let outputFile = (0, import_node_path.join)(path, dir, normalizedOptions.output ?? "index.js");
|
|
25
|
+
await (0, import_promises.rm)((0, import_node_path.join)(path, dir), { recursive: true, force: true });
|
|
25
26
|
await (0, import_esbuild.build)({
|
|
26
27
|
entryPoints: [inputFile],
|
|
27
28
|
outfile: outputFile,
|
package/dist/run.mjs
CHANGED
|
@@ -18,9 +18,10 @@ async function bundle({ path = "", bundle: options } = {}) {
|
|
|
18
18
|
input: options
|
|
19
19
|
};
|
|
20
20
|
else normalizedOptions = options;
|
|
21
|
+
let dir = normalizedOptions.dir ?? "dist";
|
|
21
22
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
22
|
-
let outputFile = join(path,
|
|
23
|
-
await rm(join(path,
|
|
23
|
+
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
24
|
+
await rm(join(path, dir), { recursive: true, force: true });
|
|
24
25
|
await build({
|
|
25
26
|
entryPoints: [inputFile],
|
|
26
27
|
outfile: outputFile,
|
package/package.json
CHANGED
package/src/BundleConfig.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
export type BundleConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* Output directory path relative to the server config `path`.
|
|
4
|
+
*
|
|
5
|
+
* @defaultValue "dist"
|
|
6
|
+
*/
|
|
7
|
+
dir?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Input path relative to the server config `path`.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue "index.ts"
|
|
12
|
+
*/
|
|
2
13
|
input?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Output path relative to the bundle config `dir`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue "index.js"
|
|
18
|
+
*/
|
|
3
19
|
output?: string;
|
|
4
20
|
};
|
package/src/Config.ts
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
import type { BundleConfig } from "./BundleConfig";
|
|
2
2
|
|
|
3
3
|
export type Config = {
|
|
4
|
+
/** Server URL. */
|
|
4
5
|
url?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Server host.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue "localhost"
|
|
10
|
+
*/
|
|
5
11
|
host?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Server port.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue 3000
|
|
16
|
+
*/
|
|
6
17
|
port?: number;
|
|
18
|
+
/** Application path. */
|
|
7
19
|
path?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Public assets directories. If not provided, the application
|
|
22
|
+
* `path` is served as a public assets directory.
|
|
23
|
+
*/
|
|
8
24
|
dirs?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Enables single-page application (SPA) mode. If `true`, all
|
|
27
|
+
* unmatched URLs are served as "/".
|
|
28
|
+
*/
|
|
9
29
|
spa?: boolean;
|
|
30
|
+
/** Whether to log to the console. */
|
|
10
31
|
log?: boolean;
|
|
11
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Bundle config.
|
|
34
|
+
*
|
|
35
|
+
* If `undefined`, bundling is skipped.
|
|
36
|
+
* Otherwise, its type is `BundleConfig`, with the following shorthand options:
|
|
37
|
+
* If `true`, it's equivalent to `{ input: "index.ts", output: "index.js" }`.
|
|
38
|
+
* If `string`, it's equivalent to `input` in `{ input, ouput: "index.js" }`.
|
|
39
|
+
*/
|
|
40
|
+
bundle?: boolean | string | BundleConfig | undefined;
|
|
12
41
|
};
|
package/src/bundle.ts
CHANGED
|
@@ -16,10 +16,11 @@ export async function bundle({ path = "", bundle: options }: Config = {}) {
|
|
|
16
16
|
};
|
|
17
17
|
else normalizedOptions = options;
|
|
18
18
|
|
|
19
|
+
let dir = normalizedOptions.dir ?? "dist";
|
|
19
20
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
20
|
-
let outputFile = join(path,
|
|
21
|
+
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
21
22
|
|
|
22
|
-
await rm(join(path,
|
|
23
|
+
await rm(join(path, dir), { recursive: true, force: true });
|
|
23
24
|
|
|
24
25
|
await build({
|
|
25
26
|
entryPoints: [inputFile],
|