-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
103 lines (102 loc) · 2.86 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
import { ConfigEnv, UserConfigExport } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import eslintPlugin from 'vite-plugin-eslint';
import baseConfig, { projectBasePath } from './src/configs/base';
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') }]
},
css: {
preprocessorOptions: {
scss: {
// additionalData: `@import "@/styles/reset.scss";@import "@/styles/variables.scss";`
}
}
},
base:
mode === 'prod'
? `${baseConfig.cdn.host}${projectBasePath}`
: mode === 'test'
? baseConfig.publicPath
: mode === 'grey'
? baseConfig.publicPath
: './',
plugins: [
react(),
viteMockServe({
mockPath: 'mocks',
supportTs: true,
localEnabled: command === 'serve' && mode === 'mock',
prodEnabled: false
// 这样可以控制关闭mock的时候不让mock打包到最终代码内
// injectCode: `
// import { setupProdMockServer } from './mockProdServer';
// setupProdMockServer();
// `
}),
viteVConsole({
entry: resolve(__dirname, './src/main.tsx'),
localEnabled: true,
enabled:
command !== 'serve' &&
(mode === 'test' || mode === 'test1' || mode === 'alpha'),
config: {
maxLogNumber: 1000,
theme: 'light'
}
}),
eslintPlugin()
],
server: {
host: '0.0.0.0',
port: 3000,
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,
polyfillModulePreload: true,
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString();
}
}
}
}
}
};
};