-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.js
103 lines (101 loc) · 2.23 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { basename, dirname, resolve } from "node:path";
import { glob } from "glob";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
const alwaysFullReload = {
name: "always-full-reload",
handleHotUpdate({ server }) {
server.ws.send({ type: "full-reload" });
return [];
}
};
export default defineConfig({
server: {
port: process.env.PORT ?? 4030
},
build: {
target: "es2022",
outDir: resolve(process.cwd(), "dist"),
rollupOptions: {
input: (await glob("src/**/index.html")).reduce(
(put, path) => ({
...put,
[basename(dirname(path))]: path
}),
{}
)
}
},
publicDir: resolve(process.cwd(), "public"),
root: resolve(process.cwd(), "src"),
appType: "mpa",
plugins: [
alwaysFullReload,
VitePWA({
registerType: "autoUpdate",
manifestFilename: "manifest.json",
workbox: {
navigateFallbackDenylist: [/^\/login/],
runtimeCaching: [
{
urlPattern:
/^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
handler: "CacheFirst",
options: {
cacheName: "google-fonts",
expiration: {
maxEntries: 4,
maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days
}
}
},
{
urlPattern:
/^https:\/\/(?:cdn\.jsdelivr\.net|cdnjs\.cloudflare\.com|debutter\.dev\/x|unpkg\.com)\/.*/i,
handler: "CacheFirst",
options: {
cacheName: "third-party-libraries",
expiration: {
maxEntries: 4,
maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days
}
}
},
{
urlPattern: /(?:.*?)\.(?:ico|svg|png|jpe?g|gif)$/i,
handler: "CacheFirst",
options: {
cacheName: "asset-cache",
expiration: {
maxEntries: 4,
maxAgeSeconds: 24 * 60 * 60 // 24 hours
}
}
},
{
urlPattern: /(?:.*?)\.(?:html|htm|js|ts|css|scss)$/i,
handler: "NetworkFirst",
options: {
cacheName: "source-cache"
}
}
]
},
manifest: {
name: "Wonk Chat",
short_name: "Wonk Chat",
start_url: "/app/",
orientation: "portrait",
theme_color: "#5841f7",
background_color: "#000000",
icons: [
{
src: "icon.png",
sizes: "512x512",
type: "image/png"
}
]
}
})
]
});