-
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathesbuild.mjs
More file actions
40 lines (36 loc) · 1017 Bytes
/
Copy pathesbuild.mjs
File metadata and controls
40 lines (36 loc) · 1017 Bytes
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
import * as esbuild from 'esbuild';
import { rmSync } from 'node:fs';
import { compress } from 'esbuild-plugin-compress';
const args = process.argv;
const dev = args.includes('dev');
const prod = args.includes('prod');
if (dev === prod) throw "There must be one and only one of either 'dev' or 'prod' in the arguments!";
const baseOpts = {
entryPoints: ['./client/main.ts'],
platform: 'browser',
format: 'iife',
target: 'es2020',
bundle: true,
outfile: './static/pychess-variants.js',
};
if (dev) {
for (const staleAsset of [
'./static/pychess-variants.js.br',
'./static/pychess-variants.js.gz',
'./static/pychess-variants.css.br',
'./static/pychess-variants.css.gz',
]) {
rmSync(staleAsset, { force: true });
}
await esbuild.build({
...baseOpts,
sourcemap: 'inline',
});
} else {
await esbuild.build({
...baseOpts,
minify: true,
write: false,
plugins: [compress()],
});
}