-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvite.config.ts
82 lines (80 loc) · 2.09 KB
/
vite.config.ts
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
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { crx } from '@crxjs/vite-plugin';
import manifest from './manifest.json' assert { type: 'json' };
import { resolve } from 'path';
import preprocess from 'svelte-preprocess';
// Update manifest with asset paths
const manifestWithAssets = {
...manifest,
icons: {
"16": "assets/icons/icon16.png",
"48": "assets/icons/icon48.png",
"128": "assets/icons/icon128.png"
},
action: {
...manifest.action,
default_icon: {
"16": "assets/icons/icon16.png",
"48": "assets/icons/icon48.png",
"128": "assets/icons/icon128.png"
}
}
};
export default defineConfig(({ mode }) => {
return {
plugins: [
svelte({
preprocess: preprocess(),
compilerOptions: {
dev: mode === 'development'
}
}),
crx({ manifest: manifestWithAssets }),
],
build: {
outDir: 'dist',
emptyOutDir: true,
minify: mode === 'production',
sourcemap: mode === 'development',
rollupOptions: {
input: {
background: resolve(__dirname, 'src/background/index.ts'),
content: resolve(__dirname, 'src/content/index.ts'),
},
output: {
format: 'esm',
entryFileNames: (chunkInfo) => {
const folder = chunkInfo.name.includes('background') ? 'background' : 'content';
return `${folder}/[name].js`;
},
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: (assetInfo) => {
if (assetInfo.name?.includes('assets/')) {
return '[name][extname]';
}
return 'assets/[name]-[hash][extname]';
},
}
}
},
resolve: {
alias: {
'$lib': resolve(__dirname, './src/lib'),
buffer: 'buffer/',
},
},
define: {
global: 'globalThis',
'process.env.NODE_ENV': JSON.stringify(mode),
},
server: {
port: 5173,
strictPort: true,
hmr: {
port: 5173
}
},
publicDir: 'assets'
};
});