-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
53 lines (51 loc) · 1.48 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
import react from '@vitejs/plugin-react';
import { defineConfig, loadEnv } from 'vite';
import vitePluginCompression from 'vite-plugin-compression';
import { resolve } from 'path';
const baseUrl = 'react-admin-template';
export default defineConfig((config) => {
const root = process.cwd()
const env = loadEnv(config.mode, root)
console.log('env==>', env)
return {
plugins: [
react(),
vitePluginCompression({
threshold: 1024 * 10, // 对大于 10kb 的文件进行压缩
// deleteOriginFile: true,
}),
],
resolve: {
alias: {
'@': `${resolve(process.cwd(), 'src')}`,
},
},
server: {
open: true,
port: 5793,
proxy: {
'/api': {
target: "http://127.0.0.1:7001",
secure: false,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
base: config.mode === 'development' ? '/' : `/${baseUrl}/`,
build: {
outDir: `../../${baseUrl}`,
rollupOptions: {
output: {
chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
},
},
},
},
};
});