-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
51 lines (43 loc) · 1.33 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
51 lines (43 loc) · 1.33 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
44
45
46
47
48
49
50
51
import * as esbuild from 'esbuild';
import { copyFileSync, mkdirSync, cpSync } from 'fs';
const isWatch = process.argv.includes('--watch');
const buildOptions = {
entryPoints: {
'content/main': 'src/content/main.ts',
'content/page-bridge': 'src/content/page-bridge.ts',
'background/service-worker': 'src/background/service-worker.ts',
'popup/popup': 'src/popup/popup.ts',
},
bundle: true,
outdir: 'dist',
format: 'esm',
sourcemap: true,
target: 'chrome120',
minify: !isWatch,
};
async function build() {
// Build TypeScript
if (isWatch) {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
console.log('Watching for changes...');
} else {
await esbuild.build(buildOptions);
}
// Copy static files
mkdirSync('dist/popup', { recursive: true });
mkdirSync('dist/styles', { recursive: true });
mkdirSync('dist/assets', { recursive: true });
copyFileSync('manifest.json', 'dist/manifest.json');
copyFileSync('src/popup/popup.html', 'dist/popup/popup.html');
copyFileSync('src/popup/popup.css', 'dist/popup/popup.css');
copyFileSync('styles/overlay.css', 'dist/styles/overlay.css');
try {
cpSync('assets/icons', 'dist/assets/icons', { recursive: true });
} catch {}
console.log('Build complete.');
}
build().catch((e) => {
console.error(e);
process.exit(1);
});