-
Notifications
You must be signed in to change notification settings - Fork 18
/
vite.config.ts
84 lines (76 loc) · 2.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import dns from 'dns'
import fs from 'fs'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { resolve } from 'path'
import { productionHeaders, developmentHeaders } from './headers.config'
// Ensure, that vite prints "localhost" instead of 127.0.0.1
// See https://vitejs.dev/config/server-options.html#server-host
dns.setDefaultResultOrder('verbatim')
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const outDir = 'dist'
const enablePisa = env.ENABLE_PISA === 'true'
return {
build: {
chunkSizeWarningLimit: 900,
outDir,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
_scrivito_extensions: resolve(__dirname, '_scrivito_extensions.html'),
},
},
},
define: {
'import.meta.env.SCRIVITO_ORIGIN': JSON.stringify(scrivitoOrigin(env)),
'import.meta.env.SCRIVITO_TENANT': JSON.stringify(env.SCRIVITO_TENANT),
'import.meta.env.SCRIVITO_ROOT_OBJ_ID': JSON.stringify(
env.SCRIVITO_ROOT_OBJ_ID || 'c2a0aab78be05a4e',
),
'import.meta.env.ENABLE_PISA': JSON.stringify(enablePisa),
},
optimizeDeps: {
force: true,
},
plugins: [react(), writeProductionHeaders(outDir)],
preview: {
port: 8080,
strictPort: true,
},
server: {
port: 8080,
strictPort: true,
headers: developmentHeaders(),
proxy: {
'/auth': {
target: 'https://api.justrelate.com/iam/auth',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/auth/, ''),
headers: { 'X-JR-Auth-Location': 'http://localhost:8080/auth' },
},
},
},
}
})
function scrivitoOrigin(env: Record<string, string>) {
/** @see https://docs.netlify.com/configure-builds/environment-variables/ */
const netlifyDeployUrl =
env.CONTEXT === 'production' ? env.URL : env.DEPLOY_PRIME_URL
/** @see https://developers.cloudflare.com/pages/configuration/build-configuration/ */
const cloudflarePagesDeployUrl = env.CF_PAGES_URL
return env.SCRIVITO_ORIGIN || cloudflarePagesDeployUrl || netlifyDeployUrl
}
function writeProductionHeaders(outDir: string) {
return {
name: 'write-production-headers',
apply: 'build' as const,
async writeBundle() {
await fs.promises.writeFile(
resolve(__dirname, outDir, '_headers'),
productionHeaders(),
)
},
}
}