import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; // Windows 上 new URL().pathname 形如 "/D:/...",前导斜杠会让 Vite 解析成 "D:/D:/..."。 // 去掉盘符前的斜杠,避免 dev server 的 fs.allow 把真实路径判为越界(403 Restricted)。 const toFsPath = (url: URL) => decodeURIComponent(url.pathname.replace(/^\/(?=[A-Za-z]:\/)/, "")); export default defineConfig({ base: "./", assetsInclude: ["**/*.fbx", "**/*.obj", "**/*.glb", "**/*.gltf"], // 强制单一 three 实例:GLTFLoader / KTX2Loader / DRACOLoader / meshopt 等 examples/jsm 模块 // 会再次 import "three",vitest 的依赖优化器可能拆出第二份 three,导致 R3F 上下文里的 // useThree/useFrame 报 "Multiple instances of Three.js" 而失效。dedupe 保证全工程只有一份。 resolve: { dedupe: ["three", "@react-three/fiber", "@react-three/drei"], }, plugins: [react()], server: { fs: { allow: [ toFsPath(new URL(".", import.meta.url)), toFsPath(new URL("../模型库", import.meta.url)), ], }, }, test: { environment: "jsdom", globals: true, pool: "threads", maxWorkers: 1, setupFiles: "./src/test/setup.ts", }, });