-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.js
92 lines (89 loc) · 2.3 KB
/
build.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require("fs");
const esbuild = require("esbuild");
const { copy } = require("esbuild-plugin-copy");
// .mjs for better node.js support
const builds = [
{ entrypoint: 'index', extension: ".js", format: "esm", platform: "browser" },
{ entrypoint: 'index-node', extension: ".mjs", format: "esm", platform: "node" },
];
for (const build of builds) {
// release
esbuild
.build({
entryPoints: [`src/${build.entrypoint}${build.extension}`],
outdir: "dist",
outExtension: {
".js": build.extension,
},
bundle: true,
sourcemap: true,
minify: true,
splitting: build.format === "esm",
format: build.format,
platform: build.platform,
external: ["module"],
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: ["./src/generated/libavoid.wasm"],
to: ["./dist", "./examples/dist"],
},
watch: true,
}),
],
})
.then(() => {
fs.copyFile(
'./typings/libavoid.d.ts',
`./dist/${build.entrypoint}.d.ts`,
(err) => {
if (err) throw err;
}
);
fs.copyFile(
`./dist/${build.entrypoint}${build.extension}`,
`./examples/dist/${build.entrypoint}${build.extension}`,
(err) => {
if (err) throw err;
}
);
fs.copyFile(
`./dist/${build.entrypoint}${build.extension}.map`,
`./examples/dist/${build.entrypoint}${build.extension}.map`,
(err) => {
if (err) throw err;
}
);
})
.catch(() => process.exit(1));
// debug
esbuild
.build({
entryPoints: ["examples/debug-src/index.js"],
outdir: "examples/debug-dist",
outExtension: {
".js": build.extension,
},
bundle: true,
minify: false,
splitting: true,
format: build.format,
platform: "neutral",
external: ["module"],
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: [
"./examples/debug-src/generated/libavoid.wasm",
"./examples/debug-src/generated/libavoid.wasm.map",
],
to: ["./examples/debug-dist"],
},
watch: true,
}),
],
})
.catch(() => process.exit(1));
}