2025-11-06 14:57:36 +08:00
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
2025-10-30 15:34:23 +08:00
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
2025-10-15 14:07:39 +08:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import { resolve } from 'path'
|
2025-11-07 15:04:37 +08:00
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
|
|
|
|
import cesium from 'vite-plugin-cesium'
|
2025-10-15 14:07:39 +08:00
|
|
|
|
2025-11-06 14:57:36 +08:00
|
|
|
const DEFAULT_BUILD_BASE = '/bxztpc/'
|
|
|
|
|
|
|
|
|
|
const normalizeBasePath = (value) => {
|
|
|
|
|
if (!value || value === '/') {
|
|
|
|
|
return '/'
|
|
|
|
|
}
|
|
|
|
|
let base = value.trim()
|
|
|
|
|
if (!base.startsWith('/')) {
|
|
|
|
|
base = `/${base}`
|
|
|
|
|
}
|
|
|
|
|
if (!base.endsWith('/')) {
|
|
|
|
|
base = `${base}/`
|
|
|
|
|
}
|
|
|
|
|
return base
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resolveCliBase = () => {
|
|
|
|
|
const argv = process.argv || []
|
|
|
|
|
const directFlagIndex = argv.indexOf('--base')
|
|
|
|
|
if (directFlagIndex !== -1 && argv[directFlagIndex + 1]) {
|
|
|
|
|
return argv[directFlagIndex + 1]
|
|
|
|
|
}
|
|
|
|
|
const customFlagIndex = argv.indexOf('--basePath')
|
|
|
|
|
if (customFlagIndex !== -1 && argv[customFlagIndex + 1]) {
|
|
|
|
|
return argv[customFlagIndex + 1]
|
|
|
|
|
}
|
|
|
|
|
const equalArg = argv.find(arg => arg.startsWith('--base='))
|
|
|
|
|
if (equalArg) {
|
|
|
|
|
return equalArg.split('=')[1]
|
|
|
|
|
}
|
|
|
|
|
const equalCustomArg = argv.find(arg => arg.startsWith('--basePath='))
|
|
|
|
|
if (equalCustomArg) {
|
|
|
|
|
return equalCustomArg.split('=')[1]
|
|
|
|
|
}
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default defineConfig(({ command, mode }) => {
|
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
|
const baseCandidate =
|
|
|
|
|
command === 'build'
|
|
|
|
|
? resolveCliBase() ??
|
|
|
|
|
env.VITE_BASE_PATH ??
|
|
|
|
|
env.BASE_PATH ??
|
|
|
|
|
process.env.BASE_PATH ??
|
|
|
|
|
DEFAULT_BUILD_BASE
|
|
|
|
|
: '/'
|
2025-11-07 15:04:37 +08:00
|
|
|
const resolvedBase =
|
|
|
|
|
process.env.NODE_ENV === 'production' ? normalizeBasePath(baseCandidate) : '/'
|
|
|
|
|
const cesiumBaseUrl = resolvedBase === '/' ? '/cesium' : `${resolvedBase}cesium`
|
2025-11-06 14:57:36 +08:00
|
|
|
|
|
|
|
|
return {
|
2025-11-07 15:04:37 +08:00
|
|
|
base: resolvedBase,
|
2025-11-06 14:57:36 +08:00
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
|
|
|
|
AutoImport({
|
|
|
|
|
resolvers: [ElementPlusResolver()],
|
|
|
|
|
}),
|
|
|
|
|
Components({
|
|
|
|
|
resolvers: [ElementPlusResolver()],
|
|
|
|
|
}),
|
2025-11-07 15:04:37 +08:00
|
|
|
createSvgIconsPlugin({
|
|
|
|
|
iconDirs: [resolve(__dirname, 'src/assets/icons/svg')],
|
|
|
|
|
symbolId: 'icon-[dir]-[name]',
|
|
|
|
|
}),
|
|
|
|
|
cesium(),
|
2025-11-06 14:57:36 +08:00
|
|
|
],
|
2025-11-07 15:04:37 +08:00
|
|
|
define: {
|
|
|
|
|
CESIUM_BASE_URL: JSON.stringify(cesiumBaseUrl),
|
|
|
|
|
},
|
2025-11-06 14:57:36 +08:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': resolve(__dirname, 'src'),
|
|
|
|
|
'@shared': resolve(__dirname, '../shared')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
server: {
|
|
|
|
|
port: 3000,
|
|
|
|
|
open: true,
|
|
|
|
|
cors: true,
|
|
|
|
|
proxy: {
|
|
|
|
|
'/snow-ops-platform': {
|
|
|
|
|
target: 'http://8.137.54.85:8661/',
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
outDir: 'dist',
|
|
|
|
|
assetsDir: 'assets',
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
minify: 'terser',
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
chunkFileNames: 'js/[name]-[hash].js',
|
|
|
|
|
entryFileNames: 'js/[name]-[hash].js',
|
|
|
|
|
assetFileNames: '[ext]/[name]-[hash].[ext]'
|
|
|
|
|
}
|
2025-10-15 14:07:39 +08:00
|
|
|
}
|
2025-11-07 15:04:37 +08:00
|
|
|
},
|
2025-10-15 14:07:39 +08:00
|
|
|
}
|
|
|
|
|
})
|