-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
50 lines (47 loc) · 1 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
import { Plugin, defineConfig } from 'vite';
import pkg from './package.json';
const htmlReplaceTitlePlugin: Plugin = {
name: 'transform-html',
transformIndexHtml: {
order: 'pre',
handler(html: string) {
return html.replace('<title>TITLE</title>', `<title>${pkg.description}</title>`);
},
},
};
const hotReloadAssetsPlugin: Plugin = {
name: 'assets-hot-reload',
handleHotUpdate({ file, server }) {
if (file.endsWith('/public/assets.txt')) {
server.ws.send({
type: 'custom',
event: 'manifest-update',
});
return [];
}
const match = file.match(/\/public(\/assets\/.*)$/);
if (match) {
server.ws.send({
type: 'custom',
event: 'assets-update',
data: match[1],
});
return [];
}
server.ws.send({ type: 'full-reload' });
return [];
},
};
export default defineConfig({
base: './',
build: {
assetsInlineLimit: Infinity,
},
server: {
port: 80,
},
plugins: [htmlReplaceTitlePlugin, hotReloadAssetsPlugin],
define: {
BUILD_HASH: `"${Date.now()}"`,
},
});