-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathvite.config.mts
108 lines (105 loc) · 3.19 KB
/
vite.config.mts
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
/*
* @Author: zouyaoji@https://github.com/zouyaoji
* @Date: 2021-12-08 23:26:13
* @LastEditTime: 2024-01-26 14:32:32
* @LastEditors: zouyaoji [email protected]
* @Description:
* @FilePath: \vue-cesium-demo\vite.config.mts
*/
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
import vueJsx from '@vitejs/plugin-vue-jsx'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('./package.json')
const htmlPlugin = () => {
return {
name: 'html-transform',
transformIndexHtml(html) {
return html.replace(/<title>(.*?)<\/title>/, `<title>${process.env.VITE_VUE_APP_TITLE}</title>`)
}
}
}
// https://vitejs.dev/config/
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
return defineConfig({
base: process.env.VITE_VUE_ROUTER_BASE,
plugins: [
vue({
template: { transformAssetUrls }
}),
vueJsx(),
quasar({
sassVariables: true
}),
htmlPlugin()
],
resolve: {
alias: {
'@src': resolve(__dirname, './src'),
'@api': resolve(__dirname, './src/api'),
'@assets': resolve(__dirname, './src/assets'),
'@common': resolve(__dirname, './src/common'),
'@components': resolve(__dirname, './src/components'),
'@composables': resolve(__dirname, './src/composables'),
'@config': resolve(__dirname, './src/config'),
'@i18n': resolve(__dirname, './src/i18n'),
'@layouts': resolve(__dirname, './src/layouts'),
'@pages': resolve(__dirname, './src/pages'),
'@router': resolve(__dirname, './src/router'),
'@store': resolve(__dirname, './src/store'),
'@types': resolve(__dirname, './src/types'),
'@utils': resolve(__dirname, './src/utils')
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@src/assets/style/variables.scss";'
}
}
},
server: {
host: '0.0.0.0',
port: 3000,
proxy: {
'/traffictile': {
target: 'https://tm.amap.com/trafficengine/mapabc/traffictile',
changeOrigin: true,
rewrite: path => path.replace(/^\/traffictile/, '/')
},
'/v3': {
target: 'https://restapi.amap.com/v3',
changeOrigin: true,
rewrite: path => path.replace(/^\/v3/, '/')
}
}
},
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true
}
},
reportCompressedSize: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('/node_modules/')) {
const modules = ['quasar', 'vue-cesium', 'echarts', 'lodash', 'axios', 'interactjs', 'lowdb', 'pinia']
const chunk = modules.find(module => id.includes(`/node_modules/${module}`))
return chunk ? `vendor-${chunk}` : 'vendor'
}
}
}
}
},
define: {
__APP_VERSION__: JSON.stringify(packageJson.version),
'process.env': {}
}
})
}