-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathvite.config.extension.ts
More file actions
72 lines (70 loc) · 2 KB
/
vite.config.extension.ts
File metadata and controls
72 lines (70 loc) · 2 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
import { resolve } from 'node:path';
import { defineConfig, build } from 'vite';
// Custom plugin to handle multiple builds
const multiBuildPlugin = () => {
return {
name: 'multi-build',
closeBundle: async () => {
// Build content script as IIFE
console.log('\nBuilding content script as IIFE...');
await build({
configFile: false,
build: {
outDir: resolve(__dirname, 'chrome/dist'),
emptyOutDir: false,
sourcemap: false,
minify: false,
lib: {
entry: resolve(__dirname, 'chrome/src/content-script.ts'),
formats: ['iife'],
name: 'PanguContentScript',
fileName: () => 'content-script.js',
},
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
resolve: {
extensions: ['.ts', '.json'],
},
esbuild: {
target: 'chrome95',
charset: 'ascii',
},
});
},
};
};
export default defineConfig({
build: {
outDir: resolve(__dirname, 'chrome/dist'),
emptyOutDir: true,
rollupOptions: {
// Only specify entry points that Chrome loads directly
// Vite will automatically handle shared dependencies:
// - Modules used by multiple entries → assets folder with hashed names
// - Modules used by single entry → inlined into that entry
input: {
popup: resolve(__dirname, 'chrome/src/popup.ts'),
options: resolve(__dirname, 'chrome/src/options.ts'),
'service-worker': resolve(__dirname, 'chrome/src/service-worker.ts'),
},
output: {
entryFileNames: '[name].js',
chunkFileNames: 'utils/[name].js',
format: 'es',
inlineDynamicImports: false,
assetFileNames: '[name].[ext]',
},
},
target: 'chrome95',
minify: false,
sourcemap: false,
},
resolve: {
extensions: ['.ts'],
},
plugins: [multiBuildPlugin()],
});