-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.scripts.ts
More file actions
75 lines (70 loc) · 2.02 KB
/
vite.config.scripts.ts
File metadata and controls
75 lines (70 loc) · 2.02 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
import { defineConfig } from "vite";
import { resolve } from "path";
import {
copyFileSync,
mkdirSync,
existsSync,
readFileSync,
writeFileSync,
} from "fs";
// Build content script + background service worker as self-contained IIFE bundles.
// This is step 1 of the build — it also copies manifest, icons, and content styles.
function copyStaticAssets() {
return {
name: "copy-static-assets",
writeBundle() {
const distDir = resolve(__dirname, "dist");
// Copy manifest.json
const manifest = JSON.parse(
readFileSync(resolve(__dirname, "src/manifest.json"), "utf-8"),
);
writeFileSync(
resolve(distDir, "manifest.json"),
JSON.stringify(manifest, null, 2),
);
// Copy icons
const iconsDir = resolve(distDir, "icons");
if (!existsSync(iconsDir)) mkdirSync(iconsDir, { recursive: true });
const srcIcons = resolve(__dirname, "src/icons");
if (existsSync(srcIcons)) {
for (const file of ["icon16.png", "icon48.png", "icon128.png"]) {
const src = resolve(srcIcons, file);
if (existsSync(src)) copyFileSync(src, resolve(iconsDir, file));
}
}
// Copy content styles
const assetsDir = resolve(distDir, "assets");
if (!existsSync(assetsDir)) mkdirSync(assetsDir, { recursive: true });
copyFileSync(
resolve(__dirname, "src/content/styles.css"),
resolve(assetsDir, "content-styles.css"),
);
},
};
}
export default defineConfig({
plugins: [copyStaticAssets()],
build: {
outDir: "dist",
emptyOutDir: true,
lib: {
entry: {
content: resolve(__dirname, "src/content/index.ts"),
background: resolve(__dirname, "src/background/index.ts"),
},
formats: ["es"],
},
rollupOptions: {
output: {
entryFileNames: "[name].js",
// No code splitting — inline everything
inlineDynamicImports: false,
},
},
},
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
});