-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
52 lines (49 loc) · 1.22 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
const rollup = require("rollup");
const typescript = require("rollup-plugin-typescript2");
const {readdirSync} = require("fs");
function getInputOptions(file) {
return {
input: `src/ais/${file}`,
plugins: [typescript({
tsconfigOverride: {
compilerOptions: {
// tsconfig.json has module = "commonjs" which is for worker code
// "esnext" is needed for rollup
module: "esnext",
target: "es2020"
}
}
})],
};
}
function getOutputOptions(file) {
return {
file: `dist/${file.replace(/ts$/, "js")}`,
format: "cjs",
intro: "(() => {",
outro: "})()",
sourcemap: true,
};
}
readdirSync("src/ais").forEach(async (ai) => {
if (process.argv[2] === "watch") {
(await rollup.watch({
...getInputOptions(ai),
output: getOutputOptions(ai),
watch: {
buildDelay: 1000,
},
})).on("event", ({ result, code }) => {
if (code === "BUNDLE_END") {
console.log(`Finished building ${ai}`);
}
if (result) {
result.close();
}
});
} else {
const bundle = await rollup.rollup(getInputOptions(ai));
await bundle.write(getOutputOptions(ai));
await bundle.close();
}
});