-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
68 lines (67 loc) · 1.83 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
import { fileURLToPath, URL } from 'node:url';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { defineConfig } from 'vite';
import livereload from 'rollup-plugin-livereload';
import zipPack from 'vite-plugin-zip-pack';
import fg from 'fast-glob';
const args = process.argv.slice(2);
const isWatch = args[1] === '--watch';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
viteStaticCopy({
targets: [
{ src: './theme.json', dest: './' },
{ src: './README*.md', dest: './' },
{ src: './preview.png', dest: './' },
{ src: './config.json', dest: './' },
],
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
// 设置入口文件
emptyOutDir: false,
// 打包文件所在目录
outDir: isWatch ? 'dev' : 'dist',
minify: true,
sourcemap: true,
rollupOptions: {
input: 'src/main.ts',
plugins: isWatch
? [
livereload('./dev'),
{
//监听静态资源文件
name: 'watch-external',
async buildStart() {
const files = await fg([
'public/**',
'README*.md',
'plugin.json',
'icon.png',
'preview.png',
]);
for (const file of files) {
this.addWatchFile(file);
}
},
},
]
: [zipPack({ inDir: './dist', outDir: './', outFileName: 'package.zip' })],
output: {
assetFileNames: assetInfo => {
return assetInfo.name?.endsWith('.css') ? 'theme.css' : 'assets/[name][extname]';
},
entryFileNames: 'theme.js',
},
},
},
server: {
port: 5173,
},
});