2026-10-30 09:58:29 +08:00
|
|
|
|
// CESIUM_BASE_URL 由 vite-plugin-cesium 自动注入(值为 base + '/cesium/',小写带尾斜杠)
|
|
|
|
|
|
// 手动覆写会与 viteStaticCopy 的小写 cesium/ 目标路径冲突,因此注释掉
|
2026-04-17 17:20:41 +08:00
|
|
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
|
|
|
|
import react from '@vitejs/plugin-react';
|
2026-04-21 14:57:52 +08:00
|
|
|
|
import path, { resolve } from 'path';
|
|
|
|
|
|
import { defineConfig, loadEnv } from 'vite';
|
2026-05-12 08:34:13 +08:00
|
|
|
|
import cesiumPlugin from 'vite-plugin-cesium';
|
|
|
|
|
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
2026-04-24 16:18:24 +08:00
|
|
|
|
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
// Vite 配置 - 性能优化版
|
|
|
|
|
|
// - 代码分包 (manualChunks)
|
|
|
|
|
|
// - 路径别名
|
|
|
|
|
|
// - CSS 代码分割
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
const ENV = { DEV: 'development', PROD: 'production' };
|
2026-04-17 17:20:41 +08:00
|
|
|
|
|
2026-04-21 14:57:52 +08:00
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
|
const env = loadEnv(mode, '.', '');
|
|
|
|
|
|
return {
|
2026-07-13 16:25:44 +08:00
|
|
|
|
|
2026-04-24 16:18:24 +08:00
|
|
|
|
plugins: [
|
|
|
|
|
|
react(),
|
|
|
|
|
|
tailwindcss(),
|
2026-07-08 11:03:29 +08:00
|
|
|
|
|
2026-10-30 09:58:29 +08:00
|
|
|
|
cesiumPlugin(),
|
|
|
|
|
|
// viteStaticCopy({
|
|
|
|
|
|
// targets: [
|
|
|
|
|
|
// {
|
|
|
|
|
|
// src: "node_modules/cesium/Build/Cesium",
|
|
|
|
|
|
// dest: ""
|
|
|
|
|
|
// }, {
|
|
|
|
|
|
// src: 'node_modules/cesium/Build/Cesium/Workers/**',
|
|
|
|
|
|
// dest: 'cesium/Workers',
|
|
|
|
|
|
// },
|
|
|
|
|
|
// {
|
|
|
|
|
|
// src: 'node_modules/cesium/Build/Cesium/ThirdParty/**',
|
|
|
|
|
|
// dest: 'cesium/ThirdParty',
|
|
|
|
|
|
// },
|
|
|
|
|
|
// {
|
|
|
|
|
|
// src: 'node_modules/cesium/Build/Cesium/Assets/**',
|
|
|
|
|
|
// dest: 'cesium/Assets',
|
|
|
|
|
|
// },
|
|
|
|
|
|
// {
|
|
|
|
|
|
// src: 'node_modules/cesium/Build/Cesium/Widgets/**',
|
|
|
|
|
|
// dest: 'cesium/Widgets',
|
|
|
|
|
|
// },
|
|
|
|
|
|
// ]
|
|
|
|
|
|
//})
|
2026-05-12 08:34:13 +08:00
|
|
|
|
|
2026-04-24 16:18:24 +08:00
|
|
|
|
],
|
|
|
|
|
|
|
2026-04-21 14:57:52 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': resolve('src'),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-04-24 16:18:24 +08:00
|
|
|
|
|
|
|
|
|
|
// ---- 性能优化构建配置 ----
|
|
|
|
|
|
build: {
|
|
|
|
|
|
// 启用 CSS 代码分割(避免样式重复打包)
|
|
|
|
|
|
cssCodeSplit: true,
|
|
|
|
|
|
// 生成 sourcemap(生产可关闭)
|
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
|
// chunk 大小警告阈值
|
|
|
|
|
|
chunkSizeWarningLimit: 1000, // KB
|
|
|
|
|
|
|
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
|
output: {
|
2026-11-12 16:02:13 +08:00
|
|
|
|
assetFileNames: 'assets/[name]-[hash][extname]'
|
2026-10-30 09:58:29 +08:00
|
|
|
|
|
2026-04-24 16:18:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
define: {
|
|
|
|
|
|
// Cesium 路径注入
|
|
|
|
|
|
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL ?? env.baseURL ?? ''),
|
2026-07-13 16:25:44 +08:00
|
|
|
|
'process.env': {}
|
2026-04-24 16:18:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-04-21 14:57:52 +08:00
|
|
|
|
server: {
|
2026-04-24 16:18:24 +08:00
|
|
|
|
port: 5173,
|
|
|
|
|
|
// HMR
|
2026-04-21 14:57:52 +08:00
|
|
|
|
hmr: process.env.DISABLE_HMR !== 'true',
|
2026-04-24 16:18:24 +08:00
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// ---- 优化用户体验 ----
|
|
|
|
|
|
esbuild: {
|
|
|
|
|
|
// 日志中排除特定的包警告
|
|
|
|
|
|
logOverride: { 'this-is-undefined-in-esm': 'silent' },
|
2026-04-21 14:57:52 +08:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2026-04-17 17:20:41 +08:00
|
|
|
|
});
|