-
Notifications
You must be signed in to change notification settings - Fork 10
/
vite.config.ts
131 lines (119 loc) · 3.07 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
127
128
129
130
131
import { UserConfig, ConfigEnv, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import eslintPlugin from 'vite-plugin-eslint'
import { viteExternalsPlugin } from 'vite-plugin-externals'
import viteSvgIcons from 'vite-plugin-svg-icons'
import { visualizer } from 'rollup-plugin-visualizer'
import importToCDN from 'vite-plugin-cdn-import'
import Components from 'unplugin-vue-components/vite'
import {
ElementPlusResolver,
AntDesignVueResolver,
} from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import path from 'path'
const nodeResolve = (dir) => path.resolve(__dirname, dir)
export default ({ mode }: ConfigEnv): UserConfig => {
process.env = {
...process.env,
...loadEnv(mode, process.cwd()),
}
const IS_PROD = ['prod', 'production'].includes(mode)
// alias
const resolve = {
alias: {
'@': nodeResolve('src'),
'~': nodeResolve('public'),
},
}
// server
const server = {
host: '0.0.0.0',
port: 3000,
proxy: {
'/api': {
target: 'http://192.168.1.163:8081/',
changeOrigin: true,
rewrite: (url) => url.replace(/^\/api/, ''),
},
},
}
const css = {
preprocessorOptions: {
less: {
additionalData: `@text-color: red;`,
// additionalData: '@import "@/assets/less/variables.less";',
javascriptEnabled: true,
},
scss: {
additionalData: `$injectedColor: orange;`,
// additionalData: `@import "@/assets/scss/variables.scss";`,
javascriptEnabled: true,
},
},
}
let plugins = [
vue(),
vueJsx(),
vueSetupExtend(),
viteSvgIcons({
// 指定需要缓存的图标文件夹
iconDirs: [nodeResolve('icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
// 是否压缩
svgoOptions: true,
}),
Components({
resolvers: [ElementPlusResolver()],
}),
ElementPlus({}),
// Components({
// resolvers: [AntDesignVueResolver()],
// }),
]
if (!IS_PROD) {
plugins = [
...plugins,
eslintPlugin({
cache: false,
include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'],
}),
]
}
if (IS_PROD) {
plugins = [
...plugins,
viteExternalsPlugin({
vue: 'Vue',
react: 'React',
'react-dom': 'ReactDOM',
// value support chain, tranform to window['React']['lazy']
lazy: ['React', 'lazy'],
}),
visualizer(),
importToCDN({
modules: [
{
name: 'cesium',
var: 'Cesium',
path: `https://cesium.com/downloads/cesiumjs/releases/1.88/Build/Cesium/Cesium.js`,
},
{
name: 'widgets',
path: `https://cesium.com/downloads/cesiumjs/releases/1.88/Build/Cesium/Widgets/widgets.css`,
},
],
}),
]
}
return {
// base: process.env.VITE_BASE_PATH,
plugins,
resolve,
css,
server,
}
}