-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
126 lines (115 loc) · 3.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { ConfigEnv, UserConfigExport } from 'vite'
// import reactRefresh from '@vitejs/plugin-react-refresh'
import react from '@vitejs/plugin-react'
import * as path from 'path'
import styleImport, { AntdResolve } from 'vite-plugin-style-import'
// import vitePluginImp from 'vite-plugin-imp'
// import usePluginImport from 'vite-plugin-importer'
// import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import { viteMockServe } from 'vite-plugin-mock'
import { dependencies } from './package.json'
const reactVendorPackages = ['react', 'react-dom', 'react-router-dom']
const reduxVendorPackages = ['@reduxjs/toolkit', 'react-redux']
// 分包
function renderChunks(deps: Record<string, string>) {
const chunks = {}
Object.keys(deps).forEach((key) => {
if (reactVendorPackages.includes(key)) return
if (reduxVendorPackages.includes(key)) return
chunks[key] = [key]
})
return chunks
}
// const uat = 'http://idata.fat4628.qa.nt.ctripcorp.com'
export default ({ command }: ConfigEnv): UserConfigExport => {
return {
resolve: {
// alias: {
// '@': path.resolve(__dirname, './src'),
// },
alias: [
{
find: '@',
replacement: path.resolve(path.resolve(__dirname), 'src'),
},
{
find: '~antd',
replacement: path.resolve(path.resolve(__dirname), 'node_modules/antd'),
},
],
},
plugins: [
// reactRefresh(),
react(),
// monacoEditorPlugin(),
viteMockServe({
// default
mockPath: 'mock',
localEnabled: command === 'serve',
}),
// vitePluginImp({
// libList: [
// {
// libName: 'antd',
// // style: (name) => {
// // if (/CompWithoutStyleFile/i.test(name)) {
// // // This will not import any style file
// // return false
// // }
// // if (name === 'col' || name === 'row') {
// // return 'antd/lib/style/index.css'
// // }
// // return `antd/es/${name}/style/index.css`
// // },
// style: (name) => `antd/es/${name}/style/css.js`,
// },
// ],
// }),
styleImport({
resolves: [AntdResolve()],
// libs: [
// {
// libraryName: 'antd',
// esModule: true,
// resolveStyle: (name) => {
// return `antd/es/${name}/style/index`
// },
// },
// ],
}),
],
build: {
target: 'es2018',
// do not set it as the context-path (this app uses "static")
assetsDir: 'assets',
rollupOptions: {
output: {
manualChunks: {
react: reactVendorPackages,
redux: reduxVendorPackages,
...renderChunks(dependencies),
},
},
},
},
css: {
preprocessorOptions: {
less: {
// 支持内联 JavaScript
javascriptEnabled: true,
},
},
},
server: {
port: 3005, // 你需要定义的端口号
// "preinstall": "npx only-allow pnpm",
proxy: {
'/api/': {
target: 'http://39.105.10.134:8998',
changeOrigin: true,
secure: false,
},
},
},
}
}