-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.ts
99 lines (97 loc) · 2.5 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import path from 'path'
import fs from 'fs'
import process from 'process'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import utools from 'vite-plugin-utools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ArcoResolver } from 'unplugin-vue-components/resolvers'
import { createStyleImportPlugin } from 'vite-plugin-style-import'
import vueJsx from '@vitejs/plugin-vue-jsx'
import postBuildPlugin from './build/postBuildPlugin'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
resolve: {
alias: {
'@': '/src'
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.vue']
},
optimizeDeps: {
include: ['@arco-design/web-vue/es']
},
// external
build: {
rollupOptions: {
external: ['electron', 'utools', 'process', 'vm', 'fs'],
output: {
sanitizeFileName(name) {
const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g
const DRIVE_LETTER_REGEX = /^[a-z]:/i
const match = DRIVE_LETTER_REGEX.exec(name)
const driveLetter = match ? match[0] : ''
// substr 是被淘汰語法,因此要改 slice
return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, '')
}
}
}
},
esbuild: {
drop: process.env.NODE_ENV === 'production' ? ['console'] : []
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
},
sass: true
}
},
server: {
port: 8083
},
plugins: [
vue(),
vueJsx(),
utools({
external: 'uTools',
preload: {
path: './public/preload.js',
watch: true,
name: 'window.preload',
minify: true
},
buildUpx: false
}),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
resolvers: [ArcoResolver()]
}),
Components({
resolvers: [
ArcoResolver({
sideEffect: true
})
]
}),
createStyleImportPlugin({
libs: [
{
libraryName: '@arco-design/web-vue',
esModule: true,
resolveStyle: (name) => {
const p = `@arco-design/web-vue/es/${name}/style/css.js`
const actualPath = path.resolve(__dirname, 'node_modules', p)
if (fs.existsSync(actualPath)) return p
return ''
}
}
]
}),
postBuildPlugin({
files: ['index.html', 'plugin.json', 'preload.js']
})
]
})