-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
44 lines (42 loc) · 887 Bytes
/
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
import * as fs from 'node:fs/promises'
import { defineConfig, type UserConfig } from 'vite'
const config: UserConfig = {
publicDir: 'dist',
base: './',
build: {
assetsDir: '',
emptyOutDir: true,
manifest: true,
outDir: 'dist',
rollupOptions: {
input: ['src/main.ts', 'src/main.css'],
},
},
server: {
open: false,
port: 8081,
strictPort: true,
host: true,
},
plugins: [
{
name: 'php',
handleHotUpdate({ file, server }) {
if (file.endsWith('.php')) {
server.ws.send({ type: 'full-reload', path: '*' })
}
},
},
],
}
// declare environment variables Vite
let started = false
export default defineConfig(async ({ command }) => {
if (!started) {
const isDev = command === 'serve'
const file = `<?php global $VITE_DEV; $VITE_DEV = ${isDev}; ?>`
await fs.writeFile('env.php', file, 'utf-8')
started = true
}
return config
})