From cc9802b75aaedc2d92e1772a1f927a34fa5de804 Mon Sep 17 00:00:00 2001 From: freedeaths Date: Thu, 16 Oct 2025 14:47:53 +0800 Subject: [PATCH] exclude vaults from dist --- vite.config.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index bc489ce..59da795 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,20 +1,35 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +import fs from 'fs'; +import path from 'path'; // https://vite.dev/config/ export default defineConfig({ - plugins: [react()], server: { host: '0.0.0.0', port: 5173, }, // 环境变量定义 - 现在使用 import.meta.env,不需要 define 了 - // 构建配置 - 排除 vault 目录 + // 构建配置 - 排除 vaults 目录但保留其他 public 文件 publicDir: 'public', build: { - copyPublicDir: true, + // 使用 Vite 插件来自定义文件复制行为 rollupOptions: { - external: ['/vaults/**'], + // 这里不需要配置,交给插件处理 }, }, + // 添加插件来过滤 public 文件 + plugins: [ + react(), + { + name: 'exclude-vaults', + writeBundle() { + // 构建完成后删除 vaults 目录 + const vaultsPath = path.resolve('dist/vaults'); + if (fs.existsSync(vaultsPath)) { + fs.rmSync(vaultsPath, { recursive: true, force: true }); + } + }, + }, + ], });