forked from NLRX-WJC/react-antd-admin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
80 lines (77 loc) · 1.9 KB
/
vite.config.js
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
import { defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import commonjs from 'vite-plugin-commonjs';
import visualizer from 'rollup-plugin-visualizer';
import path from 'path'
import fs from 'fs/promises'
// https://vitejs.dev/config/
export default defineConfig({
define: {
'process.env': process.env,
global: 'window',
},
// 静态资源引用路径,默认为"/"
base: './',
build: {
// build目录名称,默认为"dist"
outDir: 'build',
// 静态资源存放目录名称,默认为"assets"
assetsDir: 'static',
commonjsOptions: {
transformMixedEsModules: true, // 轉換兼容 commonjs
},
},
server: {
// 支持IP访问
host: true,
port: 3000,
// 设置反向代理
proxy: {
// 以下示例表示:请求URL中含有"/api",则反向代理到http://localhost
// 例如: http://localhost:3000/api/login -> http://localhost/api/login
'/api': {
target: 'http: //localhost/',
changeOrigin: true,
},
},
open: '/',
hmr: { timeout: 30000, overlay: false
},
watch: { usePolling: true
},
},
esbuild: {
loader: 'jsx',
include: /src\/.*\.jsx?$/,
exclude: [],
},
optimizeDeps: {
esbuildOptions: {
plugins: [
{
name: 'load-js-files-as-jsx',
setup(build) {
build.onLoad(
{ filter: /src\/.*\.js$/
},
async (args) => ({
loader: 'jsx',
contents: await fs.readFile(args.path, 'utf8'),
})
)
},
},
],
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
}
},
plugins: [
react(),
commonjs(),
visualizer(),
],
})