-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
127 lines (126 loc) · 3.59 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
/*
* @Author : Eug
* @Date : 2022-03-23 17:01:11
* @LastEditTime : 2023-03-20 14:15:23
* @LastEditors : eug [email protected]
* @Descripttion : Descripttion
* @FilePath : /micro-base/vite.config.ts
*/
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createHtmlPlugin } from 'vite-plugin-html';
import Components from 'unplugin-vue-components/vite';
import { ArcoResolver } from 'unplugin-vue-components/resolvers';
import { visualizer } from 'rollup-plugin-visualizer'
const { resolve } = require('path');
// TODO 解决控制台警报i8n
const getEnvFn = (mode, target) => {
return loadEnv(mode, process.cwd())[target];
};
// https://vitejs.dev/config/
export default ({ mode }) =>
defineConfig({
plugins: [
// scriptName(),
vue(),
visualizer({
filename: 'visualizer.html'
}),
createHtmlPlugin({
inject: {
data: {
VITE_APP_TITLE: getEnvFn(mode, 'VITE_APP_TITLE'),
},
},
}),
Components({
resolvers: [ArcoResolver()],
}),
],
server: {
port: 8080,
fs: {
strict: false,
},
open: true,
proxy: {
'/api': {
target: 'http://47.93.229.170:3000',
// target: 'http://localhost:3000',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
},
'/dev_base_api': {
// target: 'http://127.0.0.1:5000',
target: 'http://47.93.229.170:5000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev_base_api/, '')
},
'/dev_han_api': {
target: 'https://api.vvhan.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev_han_api/, '')
},
}
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
store: resolve(__dirname, './src/store'),
},
extensions: ['.js', '.json', '.ts', '.vue'], // 使用路径别名时想要省略的后缀名,可以自己 增减
},
// css: {
// // [WARNING] "@charset" must be the first rule in the file
// postcss: {
// plugins: [
// {
// postcssPlugin: 'internal:charset-removal',
// AtRule: {
// charset: (atRule) => {
// if (atRule.name === 'charset') {
// atRule.remove();
// }
// }
// }
// }
// ],
// },
// },
base: '/',
build: {
assetsDir: 'assets',
//设置为 false 来禁用将构建后的文件写入磁盘
write: true,
//默认情况下,若 outDir 在 root 目录下,则 Vite 会在构建时清空该目录。
emptyOutDir: true,
//启用/禁用 brotli 压缩大小报告
brotliSize: true,
//chunk 大小警告的限制
chunkSizeWarningLimit: 1000,
// 移除console
minify: 'terser',
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
rollupOptions: {
output: {
// 拆分js
manualChunks: {
lodash:['lodash'],
lowdb: ['lowdb'],
typed: ['typed.js'],
['acro-design']: ['@arco-design/web-vue'],
}
}
}
},
//调整控制台输出的级别 'info' | 'warn' | 'error' | 'silent'
logLevel: 'info',
//设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
clearScreen: true,
});