-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
118 lines (117 loc) · 3.41 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
import { baseConfig, cdnUrl, projectBasePath } from './src/config/build';
import { ConfigEnv, splitVendorChunkPlugin, UserConfigExport } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import eslintPlugin from 'vite-plugin-eslint';
import legacy from '@vitejs/plugin-legacy';
import vueJsx from '@vitejs/plugin-vue-jsx';
// import * as pkg from './package.json';
import { viteMockServe } from 'vite-plugin-mock';
import { viteVConsole } from 'vite-plugin-vconsole';
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
return {
resolve: {
alias: [{ find: '@', replacement: resolve(__dirname, './src') }]
},
base:
mode === 'prod'
? `${cdnUrl}${projectBasePath}`
: mode === 'test'
? baseConfig.publicPath + '/'
: mode === 'grey'
? baseConfig.publicPath + '/'
: './',
plugins: [
vue(),
vueJsx(),
viteMockServe({
mockPath: 'mocks',
enable: command === 'serve' && mode === 'mock'
// 这样可以控制关闭mock的时候不让mock打包到最终代码内
// injectCode: `
// import { setupProdMockServer } from './mockProdServer';
// setupProdMockServer();
// `
}),
legacy({
targets: ['defaults', 'not IE 11']
}),
viteVConsole({
entry: [resolve(__dirname, './src/main.ts')], // entry file
enabled:
(command === 'build' && mode === 'test') || command === 'serve', // build production
config: {
maxLogNumber: 1000,
theme: 'light'
}
}),
eslintPlugin(),
splitVendorChunkPlugin()
],
server: {
host: '0.0.0.0',
port: 8000,
open: true,
proxy: {
'/api': {
target:
mode === 'alpha'
? 'http://alpha-api.vadxq.com'
: mode === 'test'
? 'http://test-api.vadxq.com'
: mode === 'grey'
? 'https://api.vadxq.com'
: mode === 'prod'
? 'https://api.vadxq.com'
: 'http://0.0.0.0:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
},
'/ohter-api': {
target: 'http://other-api.vadxq.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/ohter-api/, '')
}
}
},
build: {
target: 'es2015',
outDir: './dist/',
cssCodeSplit: true,
modulePreload: {
polyfill: true
},
minify: 'terser',
cssMinify: true,
sourcemap: command !== 'serve' ? false : true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
if (
id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
.includes('pnpm')
) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[1]
.toString();
}
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString();
}
}
}
}
}
};
};