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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
| import vue from '@vitejs/plugin-vue'
| // config alias
| import path from 'path'
| import { ConfigEnv, defineConfig, UserConfigExport, loadEnv } from 'vite'
| import ViteComponents, { AntDesignVueResolver } from 'vite-plugin-components'
| // Introduce eslint plugin
| import eslintPlugin from 'vite-plugin-eslint'
| import OptimizationPersist from 'vite-plugin-optimize-persist'
| import PkgConfig from 'vite-plugin-package-config'
| import viteSvgIcons from 'vite-plugin-svg-icons'
| import { viteVConsole } from 'vite-plugin-vconsole'
| import cesium from 'vite-plugin-cesium'
| // autoImport
| import AutoImport from 'unplugin-auto-import/vite'
| import { CURRENT_CONFIG } from './src/api/http/config'
| // https://vitejs.dev/config/
| export default defineConfig(({ command, mode }) => {
| // 添加第三个参数空字符串时 '' ,会在env中包含所有环境变量;反之,只包含.env文件中配置的环境变量
| const env = loadEnv(mode, process.cwd() + '/env')
| // eslint-disable-next-line no-useless-escape
| return {
| plugins: [
| vue(),
| cesium(),
| eslintPlugin({
| fix: true,
| }),
| ViteComponents({
| customComponentResolvers: [AntDesignVueResolver()],
| }),
| viteSvgIcons({
| // 指定需要缓存的图标文件夹
| iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
| // 指定symbolId格式
| symbolId: 'icon-[dir]-[name]',
| }),
| viteVConsole({
| entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
| localEnabled: command === 'serve', // serve开发环境下
| // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
| config: {
| // vconsole 配置项
| maxLogNumber: 1000,
| theme: 'light',
| },
| }),
| AutoImport({
| dts: 'types/auto-imports.d.ts',
| imports: ['vue', 'vue-router'],
| // 解决eslint报错问题
| eslintrc: {
| // 这里先设置成true然后npm run dev 运行之后会生成 .eslintrc-auto-import.json 文件之后,在改为false
| enabled: false,
| filepath: './.eslintrc-auto-import.json', // 生成的文件路径
| globalsPropValue: true,
| },
| }),
| PkgConfig(),
| OptimizationPersist(),
| // [svgBuilder('./src/assets/icons/')] // All svg under src/icons/svg/ have been imported here, no need to import separately
| ],
| server: {
| open: true,
| host: '0.0.0.0',
| port: 8080,
| proxy: {
| [env.VITE_BASE_API]: {
| // 代理请求之后的请求地址(你的真实接口地址)
| target: env.VITE_API_URL,
| rewrite: (path) => path.replace(new RegExp(`^${env.VITE_BASE_API}`), ''),
| // 跨域
| changeOrigin: true,
| },
| },
| },
| envDir: './env',
| resolve: {
| alias: [
| {
| // https://github.com/vitejs/vite/issues/279#issuecomment-635646269
| find: '/@',
| replacement: path.resolve(__dirname, './src'),
| },
| ],
| },
| css: {
| preprocessorOptions: {
| scss: {
| // example : additionalData: `@import "./src/design/styles/variables";`
| // dont need include file extend .scss
| additionalData: '@import "./src/styles/variables";',
| },
| },
| },
| base: './',
| build: {
| target: ['es2015'], // 最低支持 es2015
| sourcemap: true,
| },
| }
| })
| // export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
| // plugins: [
| // vue(),
| // cesium(),
| // eslintPlugin({
| // fix: true
| // }),
| // ViteComponents({
| // customComponentResolvers: [AntDesignVueResolver()],
| // }),
| // viteSvgIcons({
| // // 指定需要缓存的图标文件夹
| // iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
| // // 指定symbolId格式
| // symbolId: 'icon-[dir]-[name]',
| // }),
| // viteVConsole({
| // entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
| // localEnabled: command === 'serve', // serve开发环境下
| // // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
| // config: { // vconsole 配置项
| // maxLogNumber: 1000,
| // theme: 'light'
| // }
| // }),
| // AutoImport({
| // dts: 'types/auto-imports.d.ts',
| // imports: ['vue', 'vue-router'],
| // // 解决eslint报错问题
| // eslintrc: {
| // // 这里先设置成true然后npm run dev 运行之后会生成 .eslintrc-auto-import.json 文件之后,在改为false
| // enabled: false,
| // filepath: './.eslintrc-auto-import.json', // 生成的文件路径
| // globalsPropValue: true,
| // },
| // }),
| // PkgConfig(),
| // OptimizationPersist()
| // // [svgBuilder('./src/assets/icons/')] // All svg under src/icons/svg/ have been imported here, no need to import separately
| // ],
| // server: {
| // open: true,
| // host: '0.0.0.0',
| // port: 8080,
| // proxy: {
| // '/uav': {
| // // 代理请求之后的请求地址(你的真实接口地址)
| // target: CURRENT_CONFIG.baseURL,
| // rewrite: path => path.replace(/^\/uav/, ''),
| // // 跨域
| // changeOrigin: true
| // }
| // }
| // },
| // envDir: './env',
| // resolve: {
| // alias: [{
| // // https://github.com/vitejs/vite/issues/279#issuecomment-635646269
| // find: '/@',
| // replacement: path.resolve(__dirname, './src'),
| // }
| // ]
| // },
| // css: {
| // preprocessorOptions: {
| // scss: {
| // // example : additionalData: `@import "./src/design/styles/variables";`
| // // dont need include file extend .scss
| // additionalData: '@import "./src/styles/variables";'
| // },
| // }
| // },
| // base: './',
| // build: {
| // target: ['es2015'], // 最低支持 es2015
| // sourcemap: true
| // }
| // })
|
|