-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.js
56 lines (49 loc) · 1.14 KB
/
tasks.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
const esbuild = require("esbuild");
const fs = require("fs/promises");
const sane = require("sane");
const { argv } = require("process");
const { ncp } = require("ncp");
ncp.limit = 16;
const build = () => {
const options = {
bundle: true,
define: { "process.env.NODE_ENV": process.env.NODE_ENV },
entryPoints: ["dist/index.js"],
minify: argv[3] === "production",
outfile: "dist/bundle.js",
platform: "browser",
target: "es2020",
};
esbuild.build(options).catch((err) => {
process.stderr.write(err.stderr);
process.exit(1);
});
};
const clean = async () => {
await fs.rmdir('dist', {
recursive: true,
});
await fs.mkdir('dist');
ncp("assets", "dist", (err) => err && console.error(err));
};
const watch = async () => {
const watcher = sane('dist', {glob: ['**/*.js', '!bundle.js']});
watcher.on('change', build);
};
(async () => {
const command = argv[2];
switch (command) {
case "build":
build();
break;
case "clean":
await clean();
break;
case "watch":
await watch();
break;
default:
console.log("unknown command.");
break;
}
})();