-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
66 lines (65 loc) · 1.57 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import react from '@vitejs/plugin-react-swc';
const imageRegExp = /\.(jpe?g|png|svg|gif)(\?[a-z0-9=.]+)?$/;
const fontRegExp = /\.(eot|woff|woff2|ttf)(\?.*)?$/;
const cssRegExp = /\.(css)(\?.*)?$/;
// https://vitejs.dev/config/
export default defineConfig({
// 修改引入的路径可以使用@
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
// 插件使用
plugins: [react()],
// 配置css
css: {
devSourcemap: true,
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: `@import "./src/assets/style/global.less";`
}
}
},
// 开发环境下面的配置
server: {
host: '0.0.0.0',
port: 3001,
hmr: {
overlay: false
},
// proxy: {
// '/apis': {
// target: 'https://www.baidu,com',
// changeOrigin: true,
// rewrite: path => path.replace(/^\/apis/, "")
// }
// }
},
// 生产环境下面的配置
build: {
outDir: "dist",
minify: "esbuild",
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
entryFileNames: "js/[name].[hash].chunk.js",
chunkFileNames: "js/[name].[hash].chunk.js",
assetFileNames: (assetInfo) => {
if (assetInfo.name && imageRegExp.test(assetInfo.name)) {
return "image/[name].[hash].[ext]";
} else if (assetInfo.name && fontRegExp.test(assetInfo.name)) {
return "font/[name].[hash].[ext]";
}
else if (assetInfo.name && cssRegExp.test(assetInfo.name)) {
return "css/[name].[hash].[ext]";
}
return "[name].[hash].chunk.[ext]";
},
}
}
}
})