-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
77 lines (70 loc) · 2.11 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
import path from 'node:path';
import fs from 'node:fs';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import zipPack from 'vite-plugin-zip-pack';
import { ChromeExtensionManifestPlugin, ViteIconPlugin } from './plugins';
import { isDev, resolveEntries } from './lib/utils';
import packageJson from './package.json';
const zip = process.env.EXTENSION_VERSION;
const externalPlugin = [];
if (zip) {
externalPlugin.push(zipPack({
outDir: './archives',
outFileName: `${packageJson.name}-${zip}.zip`,
}));
}
function resolveIcons() {
const target = path.resolve(__dirname, 'src/assets/icons');
// resolve target dir svg icon names
const stat = fs.statSync(target);
if (!stat.isDirectory()) {
return [];
}
const files = fs.readdirSync(target);
return files.map(file => file.replace(path.extname(file), ''));
}
// https://vitejs.dev/config/
export default defineConfig({
define: {
'__DEV__': isDev,
'__NAME__': JSON.stringify(packageJson.name),
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
},
resolve: {
alias: {
'@src': path.resolve(__dirname, 'src'),
},
},
plugins: [
react(),
...resolveIcons().map(name => ViteIconPlugin({
icon: `./src/assets/icons/${name}.svg`,
name,
})),
ChromeExtensionManifestPlugin(),
...externalPlugin,
],
build: {
watch: isDev
? {}
: undefined,
sourcemap: isDev,
rollupOptions: {
input: resolveEntries().reduce<Record<string, string>>((acc, item) => {
acc[item.name] = item.path;
return acc;
}, {}),
output: {
entryFileNames(chunkInfo) {
if (/\.html$/.test(chunkInfo.facadeModuleId)) {
return 'assets/[name]-[hash:8].js';
}
return '[name].js';
},
},
},
cssCodeSplit: true,
emptyOutDir: false,
},
});