-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
95 lines (82 loc) · 2.83 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
95 lines (82 loc) · 2.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as esbuild from 'esbuild';
import fs from 'node:fs';
import path from 'node:path';
import { createFirefoxManifest, readChromeManifest } from './scripts/manifest-utils.mjs';
const CHROME_DIST = 'dist';
const FIREFOX_DIST = 'dist-firefox';
// Ensure clean build outputs
for (const outDir of [CHROME_DIST, FIREFOX_DIST]) {
fs.rmSync(outDir, { recursive: true, force: true });
fs.mkdirSync(outDir, { recursive: true });
fs.mkdirSync(path.join(outDir, 'icons'), { recursive: true });
}
const commonOptions = {
bundle: true,
format: 'iife',
platform: 'browser',
target: ['chrome120', 'firefox128'],
treeShaking: true,
minify: false, // keep readable for Chrome Web Store review
sourcemap: false,
};
// ── Content-script bundles (injected via chrome.scripting) ──
const contentEntries = [
'src/content/core-lib.js',
'src/content/dxf-writer.js',
'src/content/acad-writers.js',
'src/content/frame-support.js',
'src/content/run-export.js',
];
for (const entry of contentEntries) {
const outName = path.basename(entry);
await esbuild.build({
...commonOptions,
entryPoints: [entry],
outfile: path.join(CHROME_DIST, outName),
});
console.log(` ✔ ${outName}`);
}
// ── Popup ──
await esbuild.build({
...commonOptions,
entryPoints: ['src/popup/popup.js'],
outfile: path.join(CHROME_DIST, 'popup.js'),
});
console.log(' ✔ popup.js');
// ── Service worker ──
await esbuild.build({
...commonOptions,
entryPoints: ['src/background/service-worker.js'],
outfile: path.join(CHROME_DIST, 'service-worker.js'),
});
console.log(' ✔ service-worker.js');
// ── Copy static assets ──
const statics = [
['manifest.json', 'manifest.json'],
['src/popup/popup.html', 'popup.html'],
['src/popup/popup.css', 'popup.css'],
['node_modules/fonteditor-core/woff2/woff2.wasm', 'woff2.wasm'],
];
for (const [src, dest] of statics) {
fs.copyFileSync(src, path.join(CHROME_DIST, dest));
console.log(` ✔ ${dest} (copy)`);
}
// Copy icons if they exist (generated by build:icons)
const iconsDir = path.join(CHROME_DIST, 'icons');
for (const size of [16, 32, 48, 128]) {
const name = `icon${size}.png`;
const src = path.join('src', 'icons', name);
if (fs.existsSync(src)) {
fs.copyFileSync(src, path.join(iconsDir, name));
console.log(` ✔ icons/${name} (copy)`);
}
}
fs.cpSync(CHROME_DIST, FIREFOX_DIST, { recursive: true });
const chromeManifest = readChromeManifest();
const firefoxManifest = createFirefoxManifest(chromeManifest);
fs.writeFileSync(
path.join(FIREFOX_DIST, 'manifest.json'),
`${JSON.stringify(firefoxManifest, null, 2)}\n`,
);
console.log(' ✔ dist-firefox/manifest.json (generated)');
console.log(`\nBuild complete → ${CHROME_DIST}/ and ${FIREFOX_DIST}/`);