-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathvite.config.ts
More file actions
64 lines (61 loc) · 1.93 KB
/
vite.config.ts
File metadata and controls
64 lines (61 loc) · 1.93 KB
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
57
58
59
60
61
62
63
64
import { devtools } from '@tanstack/devtools-vite';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import viteReact from '@vitejs/plugin-react';
import cpy from 'cpy';
import { Nitro } from 'nitro/types';
import { nitro } from 'nitro/vite';
import { resolve } from 'node:path';
import { defineConfig, loadEnv } from 'vite';
import tsConfigPaths from 'vite-tsconfig-paths';
const { nitroRetrieveServerDirHook, prismaCopyBinariesPlugin } =
createPrismaCopyBinariesPlugin();
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
const env = loadEnv(mode, process.cwd(), 'VITE_');
return {
server: {
port: env.VITE_PORT ? Number(env.VITE_PORT) : 3000,
strictPort: true,
},
plugins: [
devtools(),
tsConfigPaths(),
tanstackStart(),
nitro({
modules: [
(nitro) => {
nitro.hooks.hook('build:before', () => {
nitroRetrieveServerDirHook(nitro);
});
},
],
routeRules: { '/storybook': { redirect: '/storybook/' } },
}),
// react's vite plugin must come after start's vite plugin
viteReact({
babel: {
plugins: ['babel-plugin-react-compiler'],
},
}),
// Copy prisma binaries at the end
prismaCopyBinariesPlugin(),
],
};
});
function createPrismaCopyBinariesPlugin() {
let serverDir = '';
return {
nitroRetrieveServerDirHook: (nitro: Nitro) => {
serverDir = nitro.options.output.serverDir.replace(resolve('.'), '.');
},
prismaCopyBinariesPlugin: () => ({
name: 'prisma-copy-binaries',
writeBundle: async (outputOptions: { dir?: string }) => {
const outputDir = outputOptions.dir?.replace(resolve('.'), '.');
if (outputDir === serverDir) {
await cpy('./src/server/db/generated/**/*.node', resolve(serverDir));
}
},
}),
};
}