forked from codesandbox/static-browser-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-demo.ts
More file actions
36 lines (29 loc) · 889 Bytes
/
build-demo.ts
File metadata and controls
36 lines (29 loc) · 889 Bytes
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
import esbuild from "esbuild";
import pathUtils from "path";
import fs from "fs";
const DEMO_OUT_DIR = pathUtils.join(__dirname, "./demo-build");
fs.mkdirSync(DEMO_OUT_DIR, { recursive: true });
async function bundleDemoCode(): Promise<void> {
const entry = pathUtils.join(__dirname, "./demo/main.ts");
const result = await esbuild.build({
write: false,
bundle: true,
minify: false,
sourcemap: false,
platform: "browser",
format: "iife",
outdir: DEMO_OUT_DIR,
entryPoints: [entry],
});
const text = result.outputFiles[0].text;
const fullPath = pathUtils.join(DEMO_OUT_DIR, "main.js");
fs.writeFileSync(fullPath, text, "utf-8");
}
async function run() {
await bundleDemoCode();
fs.copyFileSync(
pathUtils.join(__dirname, "demo/index.html"),
pathUtils.join(__dirname, "demo-build/index.html")
);
}
run().catch(console.error);