-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.ts
39 lines (34 loc) · 1 KB
/
esbuild.ts
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
import { build } from "esbuild";
import svelte from "esbuild-svelte";
import { Dir, exists, existsSync, opendirSync } from "fs";
import { copyFile, mkdir, rm } from "fs/promises";
const PROD = process.env.NODE_ENV === "production";
if (existsSync("./lib")) await rm("./lib", { recursive: true });
build({
entryPoints: ["./src/index.ts"],
outfile: "./lib/index.js",
bundle: true,
target: "esnext",
format: "iife",
sourcemap: PROD ? true : "inline",
minify: PROD,
watch: !PROD,
plugins: [
svelte({
compilerOptions: {
css: true,
},
}),
],
});
async function copyStaticFiles(directory: Dir, dest = "./lib") {
for await (const entry of directory) {
if (entry.isFile()) {
await copyFile(`${directory.path}/${entry.name}`, `${dest}/${entry.name}`);
} else if (entry.isDirectory()) {
await mkdir(`${dest}/${entry.name}`, { recursive: true });
await copyStaticFiles(opendirSync(`${directory.path}/${entry.name}`), `${dest}/${entry.name}`);
}
}
}
copyStaticFiles(opendirSync("./static"));