-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
68 lines (64 loc) · 2.01 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 { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { PrimeVueResolver } from 'unplugin-vue-components/resolvers'
import { chunkSplitPlugin } from 'vite-plugin-chunk-split'
// https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts
// https://datatracker.ietf.org/doc/html/rfc2396
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$%&*+_,:;<=>?[\]^`{|}\u007F]/g // Add '_' char
// const DRIVE_LETTER_REGEX = /^[a-z]:/i
// https://vitejs.dev/config/
export default defineConfig({
build: {
rollupOptions: {
output: {
entryFileNames: 'assets/js/[name].[hash].js',
chunkFileNames: 'assets/js/[name].[hash].js',
assetFileNames(assetInfo) {
if (assetInfo.name?.endsWith('.css')) {
return 'assets/css/[name].[hash].[ext]'
}
if (['.png', '.jpg', 'jpeg', '.webp', '.svg', '.gif'].some((ext) => assetInfo.name?.endsWith(ext))) {
return 'assets/images/[name].[hash].[ext]'
}
return 'assets/[name].[hash].[ext]'
},
sanitizeFileName(name: string): string {
// 去掉无效的字符
return name.replaceAll(INVALID_CHAR_REGEX, '')
},
minifyInternalExports: true
}
},
chunkSizeWarningLimit: 2000,
cssMinify: false
},
plugins: [
vue(),
vueDevTools(),
AutoImport({
imports: ['vue'],
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver(), PrimeVueResolver()]
}),
chunkSplitPlugin()
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler' // or "modern"
}
}
}
})