This repository was archived by the owner on Aug 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
136 lines (128 loc) · 3.71 KB
/
Copy pathvite.config.ts
File metadata and controls
136 lines (128 loc) · 3.71 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { VitePWA, VitePWAOptions } from "vite-plugin-pwa";
import { readFileSync } from "fs";
import { resolve } from "path";
// Read version from package.json for cache versioning
const packageJson = JSON.parse(
readFileSync(resolve(__dirname, "package.json"), "utf-8"),
);
const appVersion = packageJson.version || "0.0.0";
const manifestForPlugIn: Partial<VitePWAOptions> = {
registerType: "autoUpdate",
includeAssets: ["favicon.ico", "yoga_icon.png"],
workbox: {
// Clean up outdated caches automatically
cleanupOutdatedCaches: true,
// Cache versioning using package.json version - updates force cache invalidation
cacheId: `youtube-chunker-v${appVersion}`,
// Runtime caching strategies
runtimeCaching: [
{
// Cache YouTube API and video data with network-first strategy
urlPattern: /^https:\/\/www\.youtube\.com\/.*/i,
handler: "NetworkFirst",
options: {
cacheName: "youtube-api-cache",
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
// Cache images with cache-first strategy
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|ico)$/,
handler: "CacheFirst",
options: {
cacheName: "image-cache",
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days
},
},
},
{
// Network-first for HTML to ensure updates are detected quickly
urlPattern: /\.html$/,
handler: "NetworkFirst",
options: {
cacheName: "html-cache",
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24, // 1 day
},
},
},
],
// Skip waiting and claim clients immediately for faster updates
skipWaiting: true,
clientsClaim: true,
},
// Development options
devOptions: {
enabled: false, // Disable SW in dev mode for easier debugging
},
manifest: {
name: "Youtube chunker",
short_name: "youtube-chunker",
description: "Youtube video chunked",
icons: [
{
src: "favicon.ico",
sizes: "64x64 32x32 24x24 16x16",
type: "image/x-icon",
},
{
src: "android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
},
],
theme_color: "#171717",
background_color: "#f0e7db",
start_url: "?fullscreen=true",
display: "standalone",
},
};
// https://vite.dev/config/
export default defineConfig({
base: "/youtube-chunk/",
plugins: [react(), VitePWA(manifestForPlugIn)],
define: {
// Inject app version into the app for display/logging
__APP_VERSION__: JSON.stringify(appVersion),
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (!id.includes("node_modules")) return;
if (id.includes("@mui/icons-material")) return "mui-icons";
if (
id.includes("@mui/material") ||
id.includes("@emotion/react") ||
id.includes("@emotion/styled")
)
return "mui-core";
if (id.includes("react-youtube")) return "react-youtube";
if (
id.includes("@reduxjs/toolkit") ||
id.includes("react-redux") ||
id.includes("redux-persist") ||
id.includes("redux-logger")
)
return "redux";
},
},
},
},
});