-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
85 lines (79 loc) · 2.51 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
83
84
85
import vue from '@vitejs/plugin-vue'
import type { RollupOptions } from 'rollup'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import viteCompression from 'vite-plugin-compression'
import { embeddedRollup } from './buildOpts'
process.env.VUE_APP_VERSION = process.env.npm_package_version
process.env.VUE_APP_AUTOR = process.env.npm_package_autor
// eslint-disable-next-line no-control-regex
const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g
const DRIVE_LETTER_REGEX = /^[a-z]:/i
function sanitizeFileName(name: string): string {
const match = DRIVE_LETTER_REGEX.exec(name)
const driveLetter = match ? match[0] : ''
// A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
// Otherwise, avoid them because they can refer to NTFS alternate data streams.
return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_REGEX, 'a')
}
export default ({ mode }: never) => {
const rollupOpts: RollupOptions = mode === 'embedded' ? embeddedRollup : { output: { sanitizeFileName: sanitizeFileName } }
return defineConfig({
base: mode === 'deploy' ? '/vue3_embedded/' : '/',
plugins: [
vue(),
AutoImport({
imports: ['vue', 'vue-router'],
resolvers: [
ElementPlusResolver(),
IconsResolver({
prefix: 'icon',
alias: {
park: 'icon-park'
}
})
]
}),
Components({
dts: true,
resolvers: [
ElementPlusResolver(),
IconsResolver({
prefix: 'icon',
alias: {
park: 'icon-park'
}
})
]
}),
Icons({
compiler: 'vue3',
autoInstall: true
}),
viteCompression({ deleteOriginFile: mode === 'embedded', threshold: 1, filter: /\.(js|mjs|json|css)$/i })
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: {
rollupOptions: rollupOpts,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version)
}
})
}