-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
165 lines (161 loc) · 5.1 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* @Author : huchaomin [email protected]
* @Date : 2023-08-06 09:42:59
* @LastEditors : huchaomin [email protected]
* @LastEditTime : 2023-10-30 14:22:42
* @Description :
*/
import { type ProxyOptions, defineConfig } from 'vite'
import type * as http from 'node:http'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import eslint from 'vite-plugin-eslint'
import stylelint from 'vite-plugin-stylelint'
import AutoImport from 'unplugin-auto-import/vite'
import autoImportStoreList from './build/autoImportStores.ts'
import { resolvePath } from './build/utils.ts'
import Components from 'unplugin-vue-components/vite'
import { vitePluginForArco } from '@arco-plugins/vite-vue'
import vuetify from 'vite-plugin-vuetify'
import { visualizer } from 'rollup-plugin-visualizer'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import viteCompression from 'vite-plugin-compression'
import VueDevTools from 'vite-plugin-vue-devtools'
import Inspect from 'vite-plugin-inspect'
import { manualChunks, chunkFileNames, assetFileNames } from './build/output.ts'
import config from './build/config.ts'
const isReport = process.env.report === 'true'
const isInspect = process.env.inspect === 'true'
const projectName = 'zg'
const { appName, apiPrefix, proxyTarget } = config[projectName]
function bypass(req: http.IncomingMessage, res: http.ServerResponse, options: ProxyOptions): void {
const proxyUrl =
new URL(options.rewrite?.(req.url) ?? req.url, options.target as string).href ?? ''
res.setHeader('X-Res-Proxyurl', proxyUrl) // 查看真实的请求地址
}
export default defineConfig((...arg) => {
console.log('vite.config.ts', arg) // {mode: 'development', command: 'serve', ssrBuild: false }
return {
define: {
API_PREFIX: JSON.stringify(apiPrefix),
APP_NAME: JSON.stringify(appName),
PROJECT_NAME: JSON.stringify(projectName),
},
resolve: {
alias: {
'@': resolvePath(__dirname, 'src'),
img: resolvePath(__dirname, 'src/assets/images'),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData:
'@use "@/assets/css/_variable.scss" as *;' +
'@use "@/assets/css/_mixin.scss" as *;' +
'@use "@/assets/css/_settings.scss" as *;',
},
// less: {
// // additionalData: '@import "@/assets/css/variable.less";',
// javascriptEnabled: true,
// // importStyle: 'less', 配合使用
// // modifyVars: {
// // 'arcoblue-6': '#000000',
// // },
// },
},
},
plugins: [
// 不要随便更改顺序否则会报错
eslint({
cache: true,
failOnError: false,
}),
stylelint({
build: true,
cacheLocation: '.cache/.stylelintcache',
}),
VueDevTools({
appendTo: 'src/router/index.ts', // 解决每第一次prebundle报错的问题 好像要在createApp前面加载
}),
vue(), // 将会把SFC的代码转换成js代码
vueJsx(), // 支持jsx
vuetify({ styles: { configFile: 'src/assets/css/_settings.scss' } }),
AutoImport({
vueTemplate: true, // Auto import inside Vue template
dts: 'types/auto-imports.d.ts',
imports: [
// https://github.com/antfu/unplugin-auto-import/tree/main/src/presets
'vue',
'vue-router',
'pinia',
'@vueuse/core',
autoImportStoreList,
],
defaultExportByFilename: true,
dirs: ['src/plugins/autoImport'],
eslintrc: {
enabled: true,
globalsPropValue: 'readonly',
filepath: 'eslintrc-auto-import.json',
},
}),
Components({
dirs: ['src/components/global'],
dts: 'types/components.d.ts',
}), // 自动引入 src/components
vitePluginForArco({
theme: '@arco-themes/vue-qingcongkeji',
// iconBox https://arco.design/iconbox/libs
}),
createSvgIconsPlugin({
iconDirs: [resolvePath(__dirname, 'src/assets/svg')],
symbolId: 'icon-[dir]-[name]',
}),
Inspect({
build: isInspect,
outputDir: '.cache/.vite-inspect',
}),
viteCompression(),
...(isReport
? [
visualizer({
open: true,
filename: '.cache/report.html',
}),
]
: []),
],
build: {
reportCompressedSize: false,
rollupOptions: {
output: {
manualChunks,
chunkFileNames,
assetFileNames,
},
},
},
optimizeDeps: {
exclude: ['vuetify'],
entries: ['./src/**/*.vue'],
},
server: {
host: '0.0.0.0', // 可以用ip访问
port: 9001,
open: false,
proxy: {
// [`/${apiPrefix}/token`]: {
// target: proxyTarget,
// changeOrigin: true,
// rewrite: (p) => p.replace(new RegExp(`/${apiPrefix}/`), ''),
// },
[`/${apiPrefix}`]: {
target: proxyTarget,
changeOrigin: true,
bypass,
},
},
},
}
})