-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
161 lines (158 loc) · 4.51 KB
/
vite.config.ts
File metadata and controls
161 lines (158 loc) · 4.51 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import path from "node:path";
import { execSync } from "node:child_process";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, type PluginOption } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import svgr from "vite-plugin-svgr";
// Get git commit hash at build time
function getGitCommitHash(): string {
try {
return execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
} catch {
return "unknown";
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
svgr(),
VitePWA({
registerType: "autoUpdate",
includeAssets: [
"favicon.ico",
"apple-touch-icon-180x180.png",
"pwa-64x64.png",
"pwa-192x192.png",
"pwa-512x512.png",
"maskable-icon-512x512.png",
"icons/favicon.svg",
],
workbox: {
disableDevLogs: false,
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, // 5MB
navigateFallback: "/",
navigateFallbackDenylist: [
/^\/v1\//,
/^\/docs/,
/^\/health$/,
/^\/api-docs(\/|$)/,
],
globPatterns: ["**/*.{html,js,css,ico,png,jpg,svg,woff2,woff,ttf,webp}"],
cleanupOutdatedCaches: true,
runtimeCaching: [
{
urlPattern: ({ url, sameOrigin, request }) => {
const isApi =
url.pathname.startsWith("/v1/") ||
url.pathname.startsWith("/docs") ||
url.pathname.startsWith("/health") ||
url.pathname.startsWith("/api-docs");
return sameOrigin && !isApi && request.mode === "navigate";
},
handler: "NetworkFirst",
options: {
cacheName: "html-pages",
expiration: {
maxAgeSeconds: 600, // 10 minutes
},
cacheableResponse: {
statuses: [200],
},
},
},
{
urlPattern: ({ url, sameOrigin }) => {
const isApi =
url.pathname.startsWith("/v1/") ||
url.pathname.startsWith("/docs") ||
url.pathname.startsWith("/health") ||
url.pathname.startsWith("/api-docs");
return (
sameOrigin &&
!isApi &&
(url.pathname.endsWith(".js") ||
url.pathname.endsWith(".css") ||
url.pathname.endsWith(".png") ||
url.pathname.endsWith(".svg") ||
url.pathname.endsWith(".jpg") ||
url.pathname.endsWith(".webp") ||
url.pathname.endsWith(".woff") ||
url.pathname.endsWith(".woff2"))
);
},
handler: "CacheFirst",
options: {
cacheName: "static-resources",
expiration: {
maxEntries: 500,
maxAgeSeconds: 604800, // 7 days
},
cacheableResponse: {
statuses: [200],
},
},
},
],
},
manifest: {
name: "NEAR AI",
short_name: "NEAR AI",
description: "NEAR AI Private Chat",
theme_color: "#171717",
background_color: "#171717",
display: "standalone",
start_url: "/",
orientation: "portrait",
icons: [
{
src: "pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png",
},
{
src: "maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
{
src: "apple-touch-icon-180x180.png",
sizes: "180x180",
type: "image/png",
},
],
},
}) as PluginOption,
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
define: {
__GIT_COMMIT_HASH__: JSON.stringify(getGitCommitHash()),
},
build: {
sourcemap: true,
rollupOptions: {
external: [
"@tauri-apps/plugin-notification",
"@tauri-apps/plugin-updater",
"@tauri-apps/plugin-process",
],
},
},
});