-
Notifications
You must be signed in to change notification settings - Fork 81
/
vite.config.ts
127 lines (116 loc) · 2.95 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import dts from 'vite-plugin-dts'
import checker from 'vite-plugin-checker'
import zipPack from 'vite-plugin-zip-pack'
import { visualizer } from 'rollup-plugin-visualizer'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig(({ mode }) => {
const isLibMode = mode === 'lib'
// 插件配置
const commonPlugins = [
zipPack({ outFileName: `lew-ui_${mode}.zip` }),
vue(),
vueJsx(),
AutoImport({ imports: ['vue', 'vue-router'] }),
checker({ typescript: true })
]
const libPlugins = isLibMode ? [
dts({
include: ['lib/**/*.vue', 'lib/**/*.ts', 'lib/**/*.tsx'],
exclude: ['lib/docs/**/*']
})
] : []
// 构建配置
const libBuildOptions = {
lib: {
entry: fileURLToPath(new URL('./lib/index.ts', import.meta.url)),
name: 'lew-ui',
fileName: 'index'
},
rollupOptions: {
external: ['vue'],
output: { globals: { vue: 'Vue' } }
},
copyPublicDir: false // lib模式下不复制public文件夹
}
const docsBuildOptions = {
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/static/[name]-[hash].[ext]',
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
}
}
}
}
}
return {
base: '',
// 开发服务器配置
server: {
open: true,
port: 10034,
hmr: true,
proxy: {
'/api_admin': {
target: 'https://app.tngeek.com/api_admin',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api_admin/, '')
},
'/api_sso': {
target: 'https://app.tngeek.com/api_sso',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api_sso/, '')
}
}
},
// CSS 配置
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
}
},
// 路径解析配置
resolve: {
alias: {
'lew-ui': fileURLToPath(new URL('./lib', import.meta.url)),
'@': fileURLToPath(new URL('./lib/docs', import.meta.url))
}
},
// 插件配置
plugins: [
...commonPlugins,
...libPlugins,
visualizer({
open: false,
filename: 'stats.html',
gzipSize: true,
brotliSize: true
})
],
// 构建配置
build: {
...(isLibMode ? libBuildOptions : docsBuildOptions),
minify: 'terser',
emptyOutDir: true,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
}
}
})