-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathvite.config.js
45 lines (42 loc) · 1.27 KB
/
vite.config.js
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 { fileURLToPath, URL } from 'node:url'
import { writeFileSync } from 'node:fs'
import path from 'path';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
const generateConfig = () => ({
socket: process.env.SOCKETURL || "ws://192.168.31.64:3000/ws",
apiURL: process.env.APIURL || "http://192.168.31.64:3000",
});
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
{
name: 'dynamic-config-json',
configureServer (server) {
// dynamic `config.json` for dev
server.middlewares.use((req, res, next) => {
if (req.url === '/config.json') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(generateConfig()));
} else {
next();
}
});
},
closeBundle () {
// static `config.json` for prod
const configPath = path.resolve(__dirname, 'dist/config.json');
writeFileSync(configPath, JSON.stringify(generateConfig(), null, 2));
console.log('Generated config.json:', generateConfig());
},
},
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
})