-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
43 lines (39 loc) · 1.09 KB
/
Copy pathbuild.ts
File metadata and controls
43 lines (39 loc) · 1.09 KB
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
#!/usr/bin/env node
import { rmSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { context } from 'esbuild';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isProduction = process.env.NODE_ENV === 'production';
try {
rmSync(path.resolve('public', 'build'), { recursive: true });
rmSync(path.resolve('public', '_metadata'), { recursive: true });
} catch {
//
}
const ctx = await context({
entryPoints: [
path.resolve(__dirname, 'source', 'service-worker.ts'),
path.resolve(__dirname, 'source', 'links-popup.ts'),
path.resolve(__dirname, 'source', 'options.ts'),
],
bundle: true,
minify: false,
format: 'esm',
splitting: true,
sourcemap: isProduction ? false : 'inline',
target: ['chrome120', 'firefox120'],
logLevel: 'info',
legalComments: 'none',
outdir: path.resolve(__dirname, 'public', 'build'),
}).catch((error) => {
console.error(error);
process.exit(1);
});
if (isProduction) {
await ctx.rebuild();
await ctx.dispose();
} else {
await ctx.watch();
}