-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbundle.ts
More file actions
71 lines (59 loc) · 1.47 KB
/
bundle.ts
File metadata and controls
71 lines (59 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// see TRANSPILATION.md
import * as esbuild from "esbuild";
import readline from "readline";
import { sassPlugin } from "esbuild-sass-plugin";
const log = (...args: any) => console.log("bundle.ts:", ...args);
const watch = process.argv.includes("--watch");
async function getEntryPointsFromStdin(): Promise<string[]> {
const rl = readline.createInterface({
input: process.stdin,
terminal: false,
});
const entries: string[] = [];
for await (const line of rl) {
const trimmed = line.trim().replace(/^\.\//, "");
if (trimmed) {
entries.push(trimmed);
}
}
return entries;
}
const entryPoints = await getEntryPointsFromStdin();
log("Entry points count:", entryPoints.length);
if (entryPoints.length === 0) {
log("No entry points found. Exiting.");
process.exit(0);
}
log(`
${entryPoints.join("\n ")}
`);
const options: esbuild.BuildOptions = {
entryPoints,
outdir: "dist",
bundle: true,
minify: false,
sourcemap: true,
target: "esnext",
format: "esm",
plugins: [sassPlugin()],
loader: {
".js": "jsx",
".jsx": "jsx",
".scss": "css",
},
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
entryNames: "[name].bundle",
jsxFactory: "React.createElement",
jsxFragment: "React.Fragment",
};
if (watch) {
const ctx = await esbuild.context(options);
log(`watch mode: ON`);
log("exbuilddone2");
await ctx.watch();
} else {
await esbuild.build(options);
log(`no watch mode: DONE`);
}