Open History to see the last commit
1import url from 'node:url'
2import path from 'node:path'
3import { defineConfig } from 'vite'
4import react from '@vitejs/plugin-react'
5import { tanstackRouter } from '@tanstack/router-plugin/vite'
6import type { BuildEnvironmentOptions } from 'vite'
7β
8const __filename = url.fileURLToPath(import.meta.url)
9const __dirname = path.dirname(__filename)
10β
11// Client Build Configuration
12const clientBuildConfig: BuildEnvironmentOptions = {
13 outDir: 'dist/client',
14 emitAssets: true,
15 copyPublicDir: true,
16 emptyOutDir: true,
17}
18β
19// Server Build Configuration
20const serverBuildConfig: BuildEnvironmentOptions = {
21 ssr: true,
22 outDir: 'dist/server',
23 copyPublicDir: false,
24 emptyOutDir: true,
25 rollupOptions: {
26 input: path.resolve(__dirname, 'src/server/server.ts'),
27 output: {
28 entryFileNames: '[name].js',
29 chunkFileNames: 'assets/[name]-[hash].js',
30 assetFileNames: 'assets/[name]-[hash][extname]',
31 },
32 },
33}
34β
35// https://vitejs.dev/config/
36export default defineConfig((configEnv) => {
37 return {
38 plugins: [
39 tanstackRouter({
40 target: 'react',
41 autoCodeSplitting: true,
42 }),
43 react(),
44 ],
45 build: configEnv.mode === 'server' ? serverBuildConfig : clientBuildConfig,
46 }
47})