-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-scripts.mjs
More file actions
40 lines (36 loc) · 1.26 KB
/
Copy pathbuild-scripts.mjs
File metadata and controls
40 lines (36 loc) · 1.26 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
import { build } from 'esbuild';
import fs from 'fs';
async function buildExtension() {
try {
// Build content script (IIFE format required for content script injection)
await build({
entryPoints: ['src/content/index.ts'],
bundle: true,
outfile: 'dist/content.js',
target: 'chrome100',
format: 'iife',
minify: true,
});
// Copy content styles
fs.copyFileSync('src/content/styles.css', 'dist/content-styles.css');
// Build background service worker
// IMPORTANT: Service workers MUST NOT be obfuscated — Chrome's MV3 worker
// runtime rejects scripts that use control-flow flattening, dead code injection,
// or self-defending patterns (status code 15). We only minify it.
await build({
entryPoints: ['src/background/index.ts'],
bundle: true,
outfile: 'dist/background.js',
target: 'chrome100',
format: 'iife',
minify: true,
});
// Removed obfuscation to comply with Chrome Web Store policies.
// The code is minified by esbuild, which safely reduces file size.
console.log('✅ Extension built and minified safely. Ready for Web Store.');
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
}
}
buildExtension();