-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
72 lines (71 loc) · 2.36 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path, { resolve } from 'path';
import viteCompression from 'vite-plugin-compression';
export default defineConfig({
plugins: [vue(), viteCompression()],
base: process.env.NODE_ENV === 'production' ? '/' : '', // 设置打包路径
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
assets: resolve(__dirname, 'src/assets'),
view: resolve(__dirname, 'src/view'),
comp: resolve(__dirname, 'src/components'),
utils: resolve(__dirname, 'src/utils'),
page: resolve(__dirname, 'src/page'),
api: resolve(__dirname, 'src/api'),
},
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: {
hack: `true; @import (reference) "${path.resolve('src/style/index.less')}"`,
},
},
},
},
build: {
chunkSizeWarningLimit: 500,
// 压缩
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // 打包时删除console
drop_debugger: true, // 打包时删除 debugger
pure_funcs: ['console.log'],
},
output: {
// 去掉注释内容
comments: false,
},
},
// 进行压缩计算
brotliSize: false,
cssCodeSplit: true,
// 拆分三方包
rollupOptions: {
output: {
// 拆分第三方包为单独文件,避免vendor.js文件大小,降低引入第三包组件的js大小
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
},
},
},
},
server: {
host: '0.0.0.0',
port: 3001,
proxy: {
'/api': {
target: 'https://www.example.com/',
changeOrigin: true, // 跨域设置
secure: false,
rewrite: (paths:any) => paths.replace(/^\/api/, '/'),
},
},
},
});