-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
vite.config.ts
82 lines (79 loc) · 2.29 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 vue from '@vitejs/plugin-vue';
import path from 'node:path';
import packageInfo from './package.json';
import HTMLLocation from 'rollup-plugin-html-location';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import ElementPlus from 'unplugin-element-plus/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Copy from 'rollup-plugin-copy';
import ZipPack from 'vite-plugin-zip-pack';
const productionMode = process.env.NODE_ENV === 'production';
const modeDir = productionMode ? 'build' : 'dist';
const browserName = process.env.BROWSER_ENV || 'unknown';
const isChromium = browserName === 'chrome' || browserName === 'edge';
const htmlNames = ['index'];
const jsNames = ['background'];
const pages = {};
htmlNames.forEach(name => {
pages[name] = path.resolve(__dirname, `src/${name}/index.html`);
});
jsNames.forEach(name => {
pages[name] = path.resolve(__dirname, `src/${name}/index.ts`);
});
const outDir = `${path.resolve(__dirname, modeDir, browserName)}`;
// https://vitejs.dev/config/
export default defineConfig({
build: {
outDir,
sourcemap: !productionMode,
chunkSizeWarningLimit: 1024,
rollupOptions: {
input: pages,
output: {
entryFileNames: '[name]/index.js',
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
publicDir: 'src/assets',
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
ElementPlus({}),
Copy({
targets: [
{
src: `src/manifest/${browserName}/manifest.json`,
dest: outDir,
},
],
hook: 'writeBundle',
}),
HTMLLocation({
filename: input => input.replace('src/', ''),
}),
productionMode
? ZipPack({
inDir: outDir,
outDir: 'archive',
outFileName: `selective-bookmarks-export-tool_${browserName}_v${packageInfo.version}.zip`,
})
: undefined,
],
define: {
'import.meta.env.BROWSER': JSON.stringify(browserName),
'import.meta.env.IS_CHROMIUM': isChromium,
'import.meta.env.VERSION': JSON.stringify(packageInfo.version),
},
});