-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
80 lines (78 loc) · 2.11 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
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import cesium from 'vite-plugin-cesium'
import autoImport from 'unplugin-auto-import/vite'
import { envDir, sourceDir } from './scripts/build'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, envDir)
// const isProd = mode === 'production'
return {
base: './',
envDir,
mode,
plugins: [
vue(),
cesium(),
autoImport({
imports: ['vue', 'vue-router', 'pinia'],
dts: './types/declaration-files/auto-import.d.ts',
eslintrc: {
enabled: true,
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true,
},
}),
],
resolve: {
alias: {
'@': sourceDir,
},
},
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
additionalData: '@import "./src/styles/variable.scss";',
},
},
},
server: {
host: true,
port: Number(env.VITE_APP_PORT),
proxy: {
'/openstreetmap': {
target: 'https://a.tile.openstreetmap.org/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/openstreetmap/, ''),
bypass(req, res, options) {
if (options.rewrite && req.url) {
const proxyUrl = new URL(
options.rewrite(req.url),
options.target as string,
).href
res.setHeader('x-req-proxyUrl', proxyUrl)
console.log('🚀 ~ bypass ~ proxyUrl:', proxyUrl) // 服务器打印访问代理地址
}
},
},
},
},
build: {
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
minify: 'terser',
terserOptions: {
compress: {
// drop_console: true, // 是否移除 console
drop_debugger: true,
},
},
chunkSizeWarningLimit: 600,
},
}
})