-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
67 lines (62 loc) · 1.45 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
const esbuild = require('esbuild');
const watch = !!process.argv[2]?.includes('watch');
/** @type {esbuild.BuildOptions} */
const lib = {
entryPoints: [ `${__dirname}/src/index.ts` ],
bundle: true,
format: 'esm',
treeShaking: true,
minify: false,
absWorkingDir: __dirname,
outbase: `${__dirname}/src`,
outdir: `${__dirname}/dist`,
loader: {
'.ts': 'ts'
},
tsconfig: `${__dirname}/tsconfig.json`,
};
const worker = {
entryPoints: [ `${__dirname}/src/worker.ts` ],
bundle: true,
format: 'esm',
treeShaking: true,
minify: true,
absWorkingDir: __dirname,
outbase: `${__dirname}/src`,
outdir: `${__dirname}/dist`,
loader: {
'.ts': 'ts'
},
tsconfig: `${__dirname}/tsconfig.json`,
};
const opfsWorker = {
entryPoints: [ `${__dirname}/src/opfs-worker.ts` ],
bundle: true,
format: 'esm',
treeShaking: true,
minify: true,
absWorkingDir: __dirname,
outbase: `${__dirname}/src`,
outdir: `${__dirname}/dist`,
loader: {
'.ts': 'ts'
},
tsconfig: `${__dirname}/tsconfig.json`,
};
(async () => {
console.log('building...', { watch });
if (!watch) {
await esbuild.build(lib);
await esbuild.build(worker);
await esbuild.build(opfsWorker);
console.log('done');
} else {
const libCtx = await esbuild.context(lib);
await libCtx.watch();
const workerCtx = await esbuild.context(worker);
await workerCtx.watch();
const opfsWorkerCtx = await esbuild.context(opfsWorker);
await opfsWorkerCtx.watch();
console.log('watching...');
}
})();