-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathvite.config.ts
More file actions
45 lines (40 loc) · 1.28 KB
/
vite.config.ts
File metadata and controls
45 lines (40 loc) · 1.28 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
import NodeChildProcess from 'node:child_process'
import NodeProcess from 'node:process'
import { cloudflare } from '@cloudflare/vite-plugin'
import { defineConfig, loadEnv } from 'vite'
import vitePluginChromiumDevTools from 'vite-plugin-devtools-json'
const commitSha =
NodeChildProcess.execSync('git rev-parse --short HEAD').toString().trim() ||
NodeProcess.env.CF_PAGES_COMMIT_SHA?.slice(0, 7)
const [, , , ...args] = NodeProcess.argv
export default defineConfig((config) => {
const env = loadEnv(config.mode, process.cwd(), '')
const lastPort = (() => {
const index = args.lastIndexOf('--port')
return index === -1 ? null : (args.at(index + 1) ?? null)
})()
const port = Number(lastPort ?? env.PORT ?? 3_000)
return {
plugins: [cloudflare(), vitePluginChromiumDevTools()],
server: {
port,
// https://hono.dev/docs/middleware/builtin/cors#using-with-vite
cors: false,
allowedHosts: config.mode === 'development' ? true : undefined,
},
define: {
__BASE_URL__: JSON.stringify(
config.mode === 'development'
? `http://localhost:${port}`
: (env.VITE_BASE_URL ?? ''),
),
__BUILD_VERSION__: JSON.stringify(commitSha ?? Date.now().toString()),
},
build: {
copyPublicDir: true,
rolldownOptions: {
output: { minify: true },
},
},
}
})