41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { defineConfig } from "vite";
|
||
import tsConfigPaths from "vite-tsconfig-paths";
|
||
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
||
import react from "@vitejs/plugin-react";
|
||
import tailwindcss from "@tailwindcss/vite";
|
||
import path from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
|
||
// 兼容 Node/Bun 双运行时的项目根定位
|
||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||
|
||
export default defineConfig({
|
||
server: { port: 3311 },
|
||
build: {
|
||
// Bun 内置模块(Bun.sql)不打包,生产用 bun 运行时启动 dist/server/server.js
|
||
rolldownOptions: { external: ["bun"] },
|
||
},
|
||
// 客户端环境用 stub 解析 "bun"(db 模块经 server fn 依赖链进入客户端图,
|
||
// 动态 import("bun") 只在服务端执行);SSR 环境把 "bun" 标记为外部模块,
|
||
// 由 Vite dev 进程(bun)原生解析 —— 否则 dev 下 module-runner 报 ERR_MODULE_NOT_FOUND
|
||
environments: {
|
||
client: {
|
||
resolve: {
|
||
alias: [{ find: /^bun$/, replacement: path.resolve(here, "src/stubs/bun-client.ts") }],
|
||
},
|
||
},
|
||
ssr: {
|
||
// builtins:把 "bun" 声明为该运行时环境的内置模块,dev 下由 bun 原生
|
||
// 解析(不进入 module-runner 的依赖图,否则报 ERR_MODULE_NOT_FOUND)。
|
||
// 注意:builtins 是覆写语义,必须带上 node:*,否则 node 内置模块失效。
|
||
resolve: { external: ["bun"], builtins: ["bun", /^node:/] },
|
||
},
|
||
},
|
||
plugins: [
|
||
tsConfigPaths({ projects: ["./tsconfig.json"] }),
|
||
tailwindcss(),
|
||
tanstackStart(),
|
||
react(),
|
||
],
|
||
});
|