-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
175 lines (172 loc) · 5.29 KB
/
vite.config.ts
File metadata and controls
175 lines (172 loc) · 5.29 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { defineConfig } from "vite";
import tsConfigPaths from "vite-tsconfig-paths";
import { VitePWA } from "vite-plugin-pwa";
export default defineConfig(() => {
// Use DEBUG environment variable for feature flags
const isDebug = (() => {
const debugValue = process.env.VITE_DEBUG || "true";
return debugValue.toLowerCase() === "true" || debugValue === "1";
})();
const devTitle = "Savr DEV - Save Articles for Reading";
const prodTitle = "Savr - Save Articles for Reading";
return {
build: {
outDir: "dist",
rollupOptions: {
input: {
main: "index.html",
},
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith(".js")) {
return "js/[name]-[hash][extname]";
}
if (assetInfo.name?.endsWith(".css")) {
return "css/[name]-[hash][extname]";
}
return "assets/[name]-[hash][extname]";
},
chunkFileNames: "js/[name]-[hash].js",
entryFileNames: "js/[name]-[hash].js",
},
},
},
base: "/", // its a bummer I have to use a non-relative base path, but I need to do this to support the url path param in production
server: {
host: "0.0.0.0",
port: 3000,
allowedHosts: true,
proxy: {},
},
appType: "spa",
preview: {
port: 3000,
},
define: {
__DEV__: true,
},
plugins: [
{
name: "serve-index",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === "/") {
req.url = "/index.html";
}
next();
});
},
},
// Dynamic favicon and title plugin
{
name: "dynamic-favicon-and-title",
transformIndexHtml(html) {
const devIcon = "/dev/favicon.ico"; // Development icon
const prodIcon = "/favicon.ico"; // Production icon
return html
.replace(
/<link rel="icon"[^>]*>/,
`<link rel="icon" type="image/svg+xml" href="${isDebug ? devIcon : prodIcon}" />`
)
.replace(/<title>.*?<\/title>/, `<title>${isDebug ? devTitle : prodTitle}</title>`);
},
},
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
VitePWA({
registerType: "autoUpdate",
includeAssets: isDebug
? ["dev/favicon.ico", "dev/apple-touch-icon.png", "dev/favicon.png", "dev/icon.png"]
: ["favicon.ico", "apple-touch-icon.png", "favicon.png", "icon.png"],
manifest: {
name: isDebug ? devTitle : prodTitle,
short_name: isDebug ? "Savr DEV" : "Savr",
description: "Save and read articles offline with a clean, distraction-free interface",
start_url: "/",
display: "standalone",
background_color: "#390055", //dark purple
theme_color: "#000000",
orientation: "any",
scope: "/",
lang: "en",
categories: ["productivity", "utilities"],
icons: isDebug
? [
{
src: "/dev/icon.png",
sizes: "192x192",
type: "image/png",
purpose: "any maskable",
},
{
src: "/dev/icon.png",
sizes: "512x512",
type: "image/png",
purpose: "any maskable",
},
]
: [
{
src: "/icon.png",
sizes: "192x192",
type: "image/png",
purpose: "any maskable",
},
{
src: "/adaptive-icon.png",
sizes: "512x512",
type: "image/png",
purpose: "any maskable",
},
],
share_target: {
action: "/share-handler",
method: "GET",
params: {
text: "text",
url: "url",
title: "title",
},
enctype: "application/x-www-form-urlencoded",
},
screenshots: [
{
src: "/screenshots/screenshots.png",
sizes: "1683x1078",
type: "image/png",
platform: "wide",
},
],
},
workbox: {
globPatterns: ["**/*.{js,css,html,ico,png,svg,webp}"],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: "CacheFirst",
options: {
cacheName: "google-fonts-cache",
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
},
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: "CacheFirst",
options: {
cacheName: "gstatic-fonts-cache",
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
},
},
],
},
}),
],
};
});