forked from elemaudio/srvb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
41 lines (36 loc) · 1.21 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { execSync } from 'node:child_process'
const currentCommit = execSync("git rev-parse --short HEAD").toString();
const date = new Date();
const dateString = `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`;
// A helper plugin which specifically watches for changes to public/dsp.main.js,
// which is built in a parallel watch job via esbuild during dev.
//
// We can still use Vite's HMR to send a custom reload-dsp event, which is caught
// inside the webview and propagated to native to reinitialize the embedded js engine.
//
// During production builds, this all gets pruned from the bundle.
function pubDirReloadPlugin() {
return {
name: 'pubDirReload',
handleHotUpdate({file, modules, server}) {
if (file.includes('public/dsp.main.js')) {
server.ws.send({
type: 'custom',
event: 'reload-dsp',
});
}
return modules;
}
};
}
// https://vitejs.dev/config/
export default defineConfig({
base: './',
define: {
__COMMIT_HASH__: JSON.stringify(currentCommit),
__BUILD_DATE__: JSON.stringify(dateString),
},
plugins: [react(), pubDirReloadPlugin()],
})