-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvite.config.ts
56 lines (54 loc) · 1.74 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
import {defineConfig, loadEnv} from 'vite'
import react from '@vitejs/plugin-react-swc'
import * as path from "path";
// https://vitejs.dev/config/
// @ts-ignore
export default ({mode}) => {
console.log('mode', loadEnv(mode, process.cwd()).VITE_BASE_URL); //127.0.0.1:9000/api
// const env = loadEnv(mode, process.cwd()) as ImportMetaEnv
return defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
build: {
target: "ESNext",
chunkSizeWarningLimit: 2000, // 消除打包大小超过500kb警告
outDir: 'dist', // 指定打包路径,默认为项目根目录下的dist目录
// minify: 'terser', // Vite 2.6.x 以上需要配置 minify:"terser",terserOptions才能生效
// terserOptions: {
// compress: {
// keep_infinity: true, // 防止 Infinity 被压缩成 1/0,这可能会导致 Chrome 上的性能问题
// drop_console: true, // 生产环境去除 console
// drop_debugger: true // 生产环境去除 debugger
// },
// format: {
// comments: false // 删除注释
// }
// },
// 静态资源打包到dist下的不同目录
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
server: {
host: '0.0.0.0',
port: 9526,
open: true,
proxy: {
'/api': {
target: 'http://127.0.0.1:9527',
changeOrigin: true,
ws: true,
rewrite: (path: string) => path.replace(/^\/api/, ''),
},
},
},
})
}