-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
56 lines (54 loc) · 1.59 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { reactRouter } from '@react-router/dev/vite'
import autoprefixer from 'autoprefixer'
import tailwindcss from 'tailwindcss'
import type { Plugin } from 'vite'
import {
defaultClientConditions,
defaultServerConditions,
defineConfig,
} from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
// This plugin fixes Vite 6's module resolution conditions which changed from v5
// React Router sets conditions: [] which breaks @prisma/client resolution
// See: https://github.com/remix-run/react-router/pull/12644
const prismaFixPlugin: Plugin = {
name: 'prisma-fix',
enforce: 'post',
config() {
return {
resolve: {
conditions: [...defaultClientConditions],
},
ssr: {
resolve: {
conditions: [...defaultServerConditions],
externalConditions: [...defaultServerConditions],
},
},
}
},
}
export default defineConfig(({ isSsrBuild, command }) => ({
build: {
rollupOptions: isSsrBuild
? {
input: './server/app.ts',
// Mark Prisma as external to prevent Vite from trying to bundle it
// This avoids ESM/CJS conflicts during build
external: ['@prisma/client-generated'],
}
: undefined,
},
css: {
postcss: {
plugins: [tailwindcss, autoprefixer],
},
},
ssr: {
noExternal: command === 'build' ? true : undefined,
// Keep Prisma external in SSR to avoid __dirname issues
// since Prisma uses __dirname which isn't available in ESM
external: ['@prisma/client-generated'],
},
plugins: [prismaFixPlugin, reactRouter(), tsconfigPaths()],
}))