-
Notifications
You must be signed in to change notification settings - Fork 16
/
vite.config.js
75 lines (73 loc) · 2.43 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
import { defineConfig } from 'vite'
import * as path from 'path'
import * as fs from 'fs'
import proxy from "./config/proxy"
import reactRefresh from '@vitejs/plugin-react-refresh'
import legacyPlugin from '@vitejs/plugin-legacy'
import vitePluginImp from 'vite-plugin-imp'
// https://cn.vitejs.dev/config/
export default defineConfig({
base: './', // index.html文件所在位置
root: './', // js导入的资源路径,src
// serve: 'production', // 环境,默认serve 时默认 'development',build 时默认 'production',遵循声明大于约定规范
resolve: {
alias: { // 别名
"layout": path.resolve(__dirname, 'src/layout'),
"configs": path.resolve(__dirname, 'src/configs'),
"components": path.resolve(__dirname, 'src/components'),
"services": path.resolve(__dirname, 'src/services'),
"pages": path.resolve(__dirname, 'src/pages'),
"types": path.resolve(__dirname, 'src/types'),
"utils": path.resolve(__dirname, 'src/utils'),
},
},
server: {
proxy: proxy, // 代理
},
define: {
'process.env.REACT_APP_IS_LOCAL': "'true'",
},
build: {
minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
manifest: false, // 是否产出maifest.json
sourcemap: false, // 是否产出soucemap.json
outDir: 'build', // 产出目录
},
plugins: [
// react-refresh插件
reactRefresh(),
legacyPlugin({
targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
}),
// 按需引用的插件, 因为主题设置不能
// vitePluginImp({
// libList: [
// {
// libName: "antd",
// style: (name) => {
// const less = fs.existsSync(path.resolve(__dirname, `node_modules/antd/es/${name}/style/index.less`))
// if (less) {
// return `antd/es/${name}/style/index.less`;
// } else {
// const css = fs.existsSync(path.resolve(__dirname, `node_modules/antd/es/${name}/style/css.js`))
// if (css) {
// return `antd/es/${name}/style/css.js`;
// } else {
// return false;
// }
// }
// },
// libDirectory: 'es',
// },
// ],
// })
],
css: {
preprocessorOptions: {
less: {
// 支持内联 JavaScript
javascriptEnabled: true,
}
}
},
})