-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
53 lines (50 loc) · 1.46 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import express from './vite-plugins/express'
import useBackend from './vite-plugins/useBackend'
import githubPages from './vite-plugins/githubPages'
import add404Html from './vite-plugins/add404Html'
const developmentPort = 3000
const previewPort = 4000
const rootDir = dirname(fileURLToPath(import.meta.url))
const srcDir = resolve(rootDir, './src')
const distDir = resolve(rootDir, './dist')
const clientDir = resolve(srcDir, './client')
const serverDir = resolve(srcDir, './server')
const publicDir = resolve(clientDir, './public')
const clientDistDir = resolve(distDir, './client')
const serverDistDir = resolve(distDir, './server')
// https://vitejs.dev/config/
export default defineConfig(({ isSsrBuild }) => ({
root: clientDir,
publicDir: publicDir,
envDir: rootDir,
envPrefix: 'PUBLIC_',
server: {
host: true,
port: developmentPort,
strictPort: true,
},
preview: {
port: previewPort,
strictPort: true,
},
build: {
outDir: isSsrBuild ? serverDistDir : clientDistDir,
emptyOutDir: true,
rollupOptions: {
...(isSsrBuild && { input: serverDir }),
},
},
plugins: [
react(),
express(serverDir),
useBackend((env) => {
return env.GITHUB_ACTIONS === 'true' ? env.OFFICIAL_BACKEND_URL : '/'
}),
githubPages(),
add404Html(),
],
}))