gitdataai/vite.config.ts
ZhenYi 066bb4e83d fix(react): add resolve.dedupe for react/react-dom to prevent CJS multi-instance
React 19.2.5 is pure CJS. Rollup's CJS→ESM interop can create separate scoped
ReactSharedInternals objects for react and react-dom, causing hooks to see a null
dispatcher on the server build. resolve.dedupe forces a single shared instance.
2026-05-12 22:41:44 +08:00

56 lines
1.3 KiB
TypeScript

import path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import {defineConfig, type Plugin} from "vite"
function tailwindEscapeFix(): Plugin {
return {
name: "tailwind-escape-fix",
enforce: "pre",
async transform(code, id) {
if (id.endsWith(".css")) {
return code.replace(/(\d)::(\d)(px|rem|em|%|vh|vw|ms|s)/g, "$1.$2$3")
}
},
}
}
export default defineConfig({
plugins: [tailwindcss(), tailwindEscapeFix(), react()],
optimizeDeps: {
entries: ["src/**/*.{ts,tsx}"],
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
dedupe: ["react", "react-dom"],
},
server: {
host: true,
port: 5080,
fs: {
deny: ["**/target/**"],
},
watch: {
ignored: ["**/libs/**", "**/target/**"],
},
hmr: {
host: "localhost",
port: 5080,
protocol: "ws",
},
proxy: {
"/api": {
target: "http://localhost:8080",
changeOrigin: true,
},
"/ws": {
target: "ws://localhost:8080",
changeOrigin: true,
ws: true,
},
},
},
})