app-template/packages/trpc/vite.config.ts

42 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
const __dirname = dirname(fileURLToPath(import.meta.url));
// 声明文件单独由 `tsc -p tsconfig.dts.json` 产出(比 vite-plugin-dts 快一个数量级)
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, "src/index.ts"),
formats: ["es"],
fileName: "index",
},
rollupOptions: {
external: [
"@app/dao",
"@app/db",
"@app/models",
"@app/types",
"@trpc/server",
"drizzle-orm",
// webdav 的 createReadStream 依赖 Node stream;打成 bundle 会把
// `import Stream from "stream"` 掏成空模块,导致 PassThrough is not a constructor
"webdav",
"stream",
/node:.*/,
],
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
},
},
// 只清 JS 产物:若 emptyOutDir=true 会先删掉 tsc 刚写的 .d.ts(构建顺序是 vite → tsc)
outDir: "dist",
emptyOutDir: false,
commonjsOptions: {
transformMixedEsModules: true,
},
},
});