@t8/serve 0.1.32 → 0.1.34
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 +1 -1
- package/dist/index.js +11 -4
- package/dist/run.cjs +24 -8
- package/dist/run.mjs +24 -8
- package/index.ts +3 -3
- package/package.json +1 -1
- package/src/Config.ts +3 -1
- package/src/bundle.ts +12 -4
- package/src/getFilePath.ts +2 -2
- package/src/getTarget.ts +1 -1
- package/src/run.ts +15 -5
- package/src/serve.ts +5 -5
- package/tsconfig.json +5 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Simple static file server + bundler, primarily for demo apps and tests, manual o
|
|
|
10
10
|
## CLI
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npx @t8/serve [url|port] [*] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path] [bundle_output_dir]] [--watch]
|
|
13
|
+
npx @t8/serve [url|port] [*] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path] [bundle_output_dir]] [--watch] [--minify]
|
|
14
14
|
# * = SPA mode: serve all unmatched paths as "/"
|
|
15
15
|
|
|
16
16
|
npx @t8/serve 3000 app
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { build, context } from "esbuild";
|
|
|
10
10
|
async function bundle({
|
|
11
11
|
path = "",
|
|
12
12
|
bundle: options,
|
|
13
|
-
watch
|
|
13
|
+
watch,
|
|
14
|
+
minify
|
|
14
15
|
} = {}) {
|
|
15
16
|
if (!options) return;
|
|
16
17
|
let normalizedOptions;
|
|
@@ -22,15 +23,21 @@ async function bundle({
|
|
|
22
23
|
else normalizedOptions = options;
|
|
23
24
|
let dir = normalizedOptions.dir ?? "dist";
|
|
24
25
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
25
|
-
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
26
26
|
await rm(join(path, dir), { recursive: true, force: true });
|
|
27
27
|
let buildOptions = {
|
|
28
28
|
entryPoints: [inputFile],
|
|
29
|
-
outfile: outputFile,
|
|
30
29
|
bundle: true,
|
|
30
|
+
format: "esm",
|
|
31
31
|
platform: "browser",
|
|
32
|
-
logLevel: "warning"
|
|
32
|
+
logLevel: "warning",
|
|
33
|
+
minify
|
|
33
34
|
};
|
|
35
|
+
if (normalizedOptions.output)
|
|
36
|
+
buildOptions.outfile = join(path, dir, normalizedOptions.output);
|
|
37
|
+
else {
|
|
38
|
+
buildOptions.outdir = join(path, dir);
|
|
39
|
+
buildOptions.splitting = true;
|
|
40
|
+
}
|
|
34
41
|
if (watch) {
|
|
35
42
|
let ctx = await context(buildOptions);
|
|
36
43
|
await ctx.watch();
|
package/dist/run.cjs
CHANGED
|
@@ -13,7 +13,8 @@ var import_esbuild = require("esbuild");
|
|
|
13
13
|
async function bundle({
|
|
14
14
|
path = "",
|
|
15
15
|
bundle: options,
|
|
16
|
-
watch
|
|
16
|
+
watch,
|
|
17
|
+
minify
|
|
17
18
|
} = {}) {
|
|
18
19
|
if (!options) return;
|
|
19
20
|
let normalizedOptions;
|
|
@@ -25,15 +26,21 @@ async function bundle({
|
|
|
25
26
|
else normalizedOptions = options;
|
|
26
27
|
let dir = normalizedOptions.dir ?? "dist";
|
|
27
28
|
let inputFile = (0, import_node_path.join)(path, normalizedOptions.input ?? "index.ts");
|
|
28
|
-
let outputFile = (0, import_node_path.join)(path, dir, normalizedOptions.output ?? "index.js");
|
|
29
29
|
await (0, import_promises.rm)((0, import_node_path.join)(path, dir), { recursive: true, force: true });
|
|
30
30
|
let buildOptions = {
|
|
31
31
|
entryPoints: [inputFile],
|
|
32
|
-
outfile: outputFile,
|
|
33
32
|
bundle: true,
|
|
33
|
+
format: "esm",
|
|
34
34
|
platform: "browser",
|
|
35
|
-
logLevel: "warning"
|
|
35
|
+
logLevel: "warning",
|
|
36
|
+
minify
|
|
36
37
|
};
|
|
38
|
+
if (normalizedOptions.output)
|
|
39
|
+
buildOptions.outfile = (0, import_node_path.join)(path, dir, normalizedOptions.output);
|
|
40
|
+
else {
|
|
41
|
+
buildOptions.outdir = (0, import_node_path.join)(path, dir);
|
|
42
|
+
buildOptions.splitting = true;
|
|
43
|
+
}
|
|
37
44
|
if (watch) {
|
|
38
45
|
let ctx = await (0, import_esbuild.context)(buildOptions);
|
|
39
46
|
await ctx.watch();
|
|
@@ -140,13 +147,21 @@ async function run() {
|
|
|
140
147
|
let [url, ...args] = process.argv.slice(2);
|
|
141
148
|
let spa = false;
|
|
142
149
|
let watch = false;
|
|
150
|
+
let minify = false;
|
|
143
151
|
if (args[0] === "*") {
|
|
144
152
|
spa = true;
|
|
145
153
|
args.shift();
|
|
146
154
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
155
|
+
while (args.at(-1)?.startsWith("--")) {
|
|
156
|
+
let arg = args.pop();
|
|
157
|
+
switch (arg) {
|
|
158
|
+
case "--watch":
|
|
159
|
+
watch = true;
|
|
160
|
+
break;
|
|
161
|
+
case "--minify":
|
|
162
|
+
minify = true;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
150
165
|
}
|
|
151
166
|
let bundleFlagIndex = args.indexOf("-b");
|
|
152
167
|
let path = args[0];
|
|
@@ -168,7 +183,8 @@ async function run() {
|
|
|
168
183
|
spa,
|
|
169
184
|
bundle: bundle2,
|
|
170
185
|
log: true,
|
|
171
|
-
watch
|
|
186
|
+
watch,
|
|
187
|
+
minify
|
|
172
188
|
});
|
|
173
189
|
}
|
|
174
190
|
run();
|
package/dist/run.mjs
CHANGED
|
@@ -12,7 +12,8 @@ import { build, context } from "esbuild";
|
|
|
12
12
|
async function bundle({
|
|
13
13
|
path = "",
|
|
14
14
|
bundle: options,
|
|
15
|
-
watch
|
|
15
|
+
watch,
|
|
16
|
+
minify
|
|
16
17
|
} = {}) {
|
|
17
18
|
if (!options) return;
|
|
18
19
|
let normalizedOptions;
|
|
@@ -24,15 +25,21 @@ async function bundle({
|
|
|
24
25
|
else normalizedOptions = options;
|
|
25
26
|
let dir = normalizedOptions.dir ?? "dist";
|
|
26
27
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
27
|
-
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
28
28
|
await rm(join(path, dir), { recursive: true, force: true });
|
|
29
29
|
let buildOptions = {
|
|
30
30
|
entryPoints: [inputFile],
|
|
31
|
-
outfile: outputFile,
|
|
32
31
|
bundle: true,
|
|
32
|
+
format: "esm",
|
|
33
33
|
platform: "browser",
|
|
34
|
-
logLevel: "warning"
|
|
34
|
+
logLevel: "warning",
|
|
35
|
+
minify
|
|
35
36
|
};
|
|
37
|
+
if (normalizedOptions.output)
|
|
38
|
+
buildOptions.outfile = join(path, dir, normalizedOptions.output);
|
|
39
|
+
else {
|
|
40
|
+
buildOptions.outdir = join(path, dir);
|
|
41
|
+
buildOptions.splitting = true;
|
|
42
|
+
}
|
|
36
43
|
if (watch) {
|
|
37
44
|
let ctx = await context(buildOptions);
|
|
38
45
|
await ctx.watch();
|
|
@@ -139,13 +146,21 @@ async function run() {
|
|
|
139
146
|
let [url, ...args] = process.argv.slice(2);
|
|
140
147
|
let spa = false;
|
|
141
148
|
let watch = false;
|
|
149
|
+
let minify = false;
|
|
142
150
|
if (args[0] === "*") {
|
|
143
151
|
spa = true;
|
|
144
152
|
args.shift();
|
|
145
153
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
while (args.at(-1)?.startsWith("--")) {
|
|
155
|
+
let arg = args.pop();
|
|
156
|
+
switch (arg) {
|
|
157
|
+
case "--watch":
|
|
158
|
+
watch = true;
|
|
159
|
+
break;
|
|
160
|
+
case "--minify":
|
|
161
|
+
minify = true;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
149
164
|
}
|
|
150
165
|
let bundleFlagIndex = args.indexOf("-b");
|
|
151
166
|
let path = args[0];
|
|
@@ -167,7 +182,8 @@ async function run() {
|
|
|
167
182
|
spa,
|
|
168
183
|
bundle: bundle2,
|
|
169
184
|
log: true,
|
|
170
|
-
watch
|
|
185
|
+
watch,
|
|
186
|
+
minify
|
|
171
187
|
});
|
|
172
188
|
}
|
|
173
189
|
run();
|
package/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./src/BundleConfig";
|
|
2
|
-
export * from "./src/Config";
|
|
3
|
-
export * from "./src/serve";
|
|
1
|
+
export * from "./src/BundleConfig.ts";
|
|
2
|
+
export * from "./src/Config.ts";
|
|
3
|
+
export * from "./src/serve.ts";
|
package/package.json
CHANGED
package/src/Config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { BundleConfig } from "./BundleConfig";
|
|
2
|
+
import type { BundleConfig } from "./BundleConfig.ts";
|
|
3
3
|
|
|
4
4
|
export type Config = {
|
|
5
5
|
/** Server URL. */
|
|
@@ -30,6 +30,8 @@ export type Config = {
|
|
|
30
30
|
spa?: boolean;
|
|
31
31
|
/** Whether to rebuild whenever the bundled files change. */
|
|
32
32
|
watch?: boolean;
|
|
33
|
+
/** Whether the bundle should be minified. */
|
|
34
|
+
minify?: boolean;
|
|
33
35
|
/** Whether to log to the console. */
|
|
34
36
|
log?: boolean;
|
|
35
37
|
/**
|
package/src/bundle.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { type BuildOptions, build, context } from "esbuild";
|
|
4
|
-
import type { BundleConfig } from "./BundleConfig";
|
|
5
|
-
import type { Config } from "./Config";
|
|
4
|
+
import type { BundleConfig } from "./BundleConfig.ts";
|
|
5
|
+
import type { Config } from "./Config.ts";
|
|
6
6
|
|
|
7
7
|
export async function bundle({
|
|
8
8
|
path = "",
|
|
9
9
|
bundle: options,
|
|
10
10
|
watch,
|
|
11
|
+
minify,
|
|
11
12
|
}: Config = {}) {
|
|
12
13
|
if (!options) return;
|
|
13
14
|
|
|
@@ -22,18 +23,25 @@ export async function bundle({
|
|
|
22
23
|
|
|
23
24
|
let dir = normalizedOptions.dir ?? "dist";
|
|
24
25
|
let inputFile = join(path, normalizedOptions.input ?? "index.ts");
|
|
25
|
-
let outputFile = join(path, dir, normalizedOptions.output ?? "index.js");
|
|
26
26
|
|
|
27
27
|
await rm(join(path, dir), { recursive: true, force: true });
|
|
28
28
|
|
|
29
29
|
let buildOptions: BuildOptions = {
|
|
30
30
|
entryPoints: [inputFile],
|
|
31
|
-
outfile: outputFile,
|
|
32
31
|
bundle: true,
|
|
32
|
+
format: "esm",
|
|
33
33
|
platform: "browser",
|
|
34
34
|
logLevel: "warning",
|
|
35
|
+
minify,
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
if (normalizedOptions.output)
|
|
39
|
+
buildOptions.outfile = join(path, dir, normalizedOptions.output);
|
|
40
|
+
else {
|
|
41
|
+
buildOptions.outdir = join(path, dir);
|
|
42
|
+
buildOptions.splitting = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
if (watch) {
|
|
38
46
|
let ctx = await context(buildOptions);
|
|
39
47
|
|
package/src/getFilePath.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import type { Config } from "./Config";
|
|
3
|
-
import { isValidFilePath } from "./isValidFilePath";
|
|
2
|
+
import type { Config } from "./Config.ts";
|
|
3
|
+
import { isValidFilePath } from "./isValidFilePath.ts";
|
|
4
4
|
|
|
5
5
|
const cwd = process.cwd();
|
|
6
6
|
|
package/src/getTarget.ts
CHANGED
package/src/run.ts
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { Config } from "./Config";
|
|
3
|
-
import { serve } from "./serve";
|
|
2
|
+
import type { Config } from "./Config.ts";
|
|
3
|
+
import { serve } from "./serve.ts";
|
|
4
4
|
|
|
5
5
|
async function run() {
|
|
6
6
|
let [url, ...args] = process.argv.slice(2);
|
|
7
7
|
let spa = false;
|
|
8
8
|
let watch = false;
|
|
9
|
+
let minify = false;
|
|
9
10
|
|
|
10
11
|
if (args[0] === "*") {
|
|
11
12
|
spa = true;
|
|
12
13
|
args.shift();
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
while (args.at(-1)?.startsWith("--")) {
|
|
17
|
+
let arg = args.pop();
|
|
18
|
+
|
|
19
|
+
switch (arg) {
|
|
20
|
+
case "--watch":
|
|
21
|
+
watch = true;
|
|
22
|
+
break;
|
|
23
|
+
case "--minify":
|
|
24
|
+
minify = true;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
let bundleFlagIndex = args.indexOf("-b");
|
|
@@ -41,6 +50,7 @@ async function run() {
|
|
|
41
50
|
bundle,
|
|
42
51
|
log: true,
|
|
43
52
|
watch,
|
|
53
|
+
minify,
|
|
44
54
|
});
|
|
45
55
|
}
|
|
46
56
|
|
package/src/serve.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createReadStream } from "node:fs";
|
|
2
2
|
import { createServer } from "node:http";
|
|
3
3
|
import { extname } from "node:path";
|
|
4
|
-
import { bundle } from "./bundle";
|
|
5
|
-
import type { Config } from "./Config";
|
|
6
|
-
import { getFilePath } from "./getFilePath";
|
|
7
|
-
import { getTarget } from "./getTarget";
|
|
8
|
-
import { mimeTypes } from "./mimeTypes";
|
|
4
|
+
import { bundle } from "./bundle.ts";
|
|
5
|
+
import type { Config } from "./Config.ts";
|
|
6
|
+
import { getFilePath } from "./getFilePath.ts";
|
|
7
|
+
import { getTarget } from "./getTarget.ts";
|
|
8
|
+
import { mimeTypes } from "./mimeTypes.ts";
|
|
9
9
|
|
|
10
10
|
export type Server = ReturnType<typeof createServer>;
|
|
11
11
|
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"include": ["index.ts", "src"],
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"noEmit": true,
|
|
4
5
|
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
5
|
-
"target": "
|
|
6
|
+
"target": "esnext",
|
|
6
7
|
"outDir": "dist",
|
|
7
|
-
"
|
|
8
|
+
"module": "nodenext",
|
|
9
|
+
"moduleResolution": "nodenext",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
8
11
|
"strict": true,
|
|
9
12
|
"noUnusedLocals": true,
|
|
10
13
|
"noUnusedParameters": true
|