import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";

export default defineConfig({
    plugins: [
        TanStackRouterVite({ target: "react", autoCodeSplitting: true }),
        react(),
    ],
    resolve: {
        // 聚珍（cjk-autospace submodule）以包名 import；运行时指向 ESM bundle，
        // 类型由 tsconfig paths 指向 dist/index.d.ts。CSS 走 index.css 相对 @import。
        alias: {
            "cjk-autospace": fileURLToPath(
                new URL("./src/lib/cjk-autospace/dist/juzhen.mjs", import.meta.url),
            ),
        },
    },
    server: {
        proxy: {
            "/api": "http://localhost:8080",
        },
    },
});
