2026-04-23 20:26:48 +08:00
|
|
|
|
import type { Plugin } from 'vite';
|
|
|
|
|
|
|
|
|
|
|
|
import { copyFileSync, mkdirSync } from 'node:fs';
|
|
|
|
|
|
import { createRequire } from 'node:module';
|
|
|
|
|
|
import { dirname, resolve } from 'node:path';
|
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
2024-07-29 00:19:26 +08:00
|
|
|
|
import { defineConfig } from '@vben/vite-config';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
2026-04-23 20:26:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 启动/构建时把 lottie-web 的 light 播放器从 node_modules 拷到 public/
|
|
|
|
|
|
* 供 loading.html 以 <script src="/lottie_light.min.js"> 方式加载。
|
|
|
|
|
|
* 直接覆盖拷贝(~170KB,<1ms),避免 mtime 粒度在部分 FS 上漏拷。
|
|
|
|
|
|
*/
|
|
|
|
|
|
function copyLottiePlayer(): Plugin {
|
|
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
|
|
const src = require.resolve('lottie-web/build/player/lottie_light.min.js');
|
|
|
|
|
|
const dest = resolve(
|
|
|
|
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
|
|
|
|
'public/lottie_light.min.js',
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
name: 'web-antd:copy-lottie-player',
|
|
|
|
|
|
configResolved() {
|
|
|
|
|
|
mkdirSync(dirname(dest), { recursive: true });
|
|
|
|
|
|
copyFileSync(src, dest);
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-13 21:00:31 +08:00
|
|
|
|
export default defineConfig(async () => {
|
|
|
|
|
|
return {
|
2024-07-29 00:19:26 +08:00
|
|
|
|
application: {},
|
2024-07-13 21:00:31 +08:00
|
|
|
|
vite: {
|
2026-04-23 20:26:48 +08:00
|
|
|
|
plugins: [copyLottiePlayer()],
|
2024-07-13 21:00:31 +08:00
|
|
|
|
server: {
|
|
|
|
|
|
proxy: {
|
2025-03-18 13:06:04 +08:00
|
|
|
|
'/admin-api': {
|
2024-07-13 21:00:31 +08:00
|
|
|
|
changeOrigin: true,
|
2025-03-18 13:06:04 +08:00
|
|
|
|
rewrite: (path) => path.replace(/^\/admin-api/, ''),
|
2024-07-28 14:29:05 +08:00
|
|
|
|
// mock代理目标地址
|
2025-03-18 13:06:04 +08:00
|
|
|
|
target: 'http://localhost:48080/admin-api',
|
2024-07-13 21:00:31 +08:00
|
|
|
|
ws: true,
|
|
|
|
|
|
},
|
2024-05-19 21:20:42 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-07-13 21:00:31 +08:00
|
|
|
|
};
|
2024-05-19 21:20:42 +08:00
|
|
|
|
});
|