-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
54 lines (47 loc) · 1.14 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
#!/usr/bin/env node
// @ts-check
import { error, log } from 'console';
import { context } from 'esbuild';
import { join } from 'path';
import prettyBytes from 'pretty-bytes';
import { argv, cwd, exit } from 'process';
const ctx = await context({
entryPoints: [join(cwd(), 'src', 'index.ts')],
outdir: join(cwd(), 'out'),
bundle: true,
minify: true,
sourcesContent: false,
allowOverwrite: true,
format: 'esm',
platform: 'node',
sourcemap: 'inline',
tsconfig: join(cwd(), 'tsconfig.json'),
packages: 'external',
metafile: true,
plugins: [
{
name: 'bundle-size',
setup: ({ onEnd }) => {
onEnd(({ errors, metafile }) => {
if (errors.length) {
error(errors);
return;
}
const size = Object.values(metafile?.outputs ?? {}).reduce(
(a, b) => a + b.bytes,
0
);
log(`Build complete with ${prettyBytes(size, { locale: 'ja' })}`);
});
},
},
],
});
process.on('beforeExit', () => {
ctx.dispose().catch(error);
});
if (!argv.includes('--watch')) {
await ctx.rebuild();
exit();
}
await ctx.watch();