Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
128 lines (124 loc) · 4.8 KB
/
Copy pathvite.config.ts
File metadata and controls
128 lines (124 loc) · 4.8 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
import { defineConfig, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { VitePWA } from "vite-plugin-pwa";
import { readFileSync } from "node:fs";
import { execSync } from "node:child_process";
import { fileURLToPath, URL } from "node:url";
// Bake the installed @ffmpeg/core version into the build so the core is served
// from a versioned URL (see src/lib/coreUrls.ts) — bumping the core then
// invalidates the runtime cache instead of serving a stale wasm forever.
const coreVersion: string = JSON.parse(
readFileSync(
fileURLToPath(new URL("./node_modules/@ffmpeg/core/package.json", import.meta.url)),
"utf8"
)
).version;
// Build-info traceability: app version + the exact commit + build time, so we can
// always tell what is live. The commit comes from Cloudflare Pages' build env, or
// from git locally, or "dev".
const appVersion: string = JSON.parse(
readFileSync(fileURLToPath(new URL("./package.json", import.meta.url)), "utf8")
).version;
const buildCommit: string =
process.env.CF_PAGES_COMMIT_SHA?.slice(0, 7) ||
(() => {
try {
return execSync("git rev-parse --short HEAD").toString().trim();
} catch {
return "dev";
}
})();
const buildTime = new Date().toISOString();
// Inject build info as <meta> tags and emit a machine-readable /version.json.
function buildInfo(): Plugin {
const info = { version: appVersion, commit: buildCommit, buildTime };
return {
name: "build-info",
transformIndexHtml() {
return [
{ tag: "meta", attrs: { name: "app-version", content: info.version }, injectTo: "head" },
{ tag: "meta", attrs: { name: "build-commit", content: info.commit }, injectTo: "head" },
{ tag: "meta", attrs: { name: "build-time", content: info.buildTime }, injectTo: "head" },
];
},
generateBundle() {
this.emitFile({
type: "asset",
fileName: "version.json",
source: JSON.stringify(info, null, 2) + "\n",
});
},
};
}
// Single-thread @ffmpeg/core (per gating spike) needs no COOP/COEP headers.
export default defineConfig({
define: {
__FFMPEG_CORE_VERSION__: JSON.stringify(coreVersion),
__APP_VERSION__: JSON.stringify(appVersion),
__BUILD_COMMIT__: JSON.stringify(buildCommit),
__BUILD_TIME__: JSON.stringify(buildTime),
},
plugins: [
buildInfo(),
react(),
tailwindcss(),
VitePWA({
// "prompt": we control when a new version activates so a reload never interrupts an
// in-progress conversion. OfflineStatus then auto-applies the update once the app is
// idle, so returning visitors still land on the latest version without clicking the
// pill. Switching to "autoUpdate" would apply updates immediately and unconditionally
// (simpler, no pill) but could reload mid-conversion and lose the work.
registerType: "prompt",
includeAssets: ["favicon/**", "logo_karaokio.png"],
manifest: {
// The app is "cdg2mp4"; Karaokio is the company/brand behind it.
name: "cdg2mp4 — CDG to MP4 Converter by Karaokio",
short_name: "cdg2mp4",
description: "Convert karaoke CDG+MP3 files to MP4 video, right in your browser.",
theme_color: "#D92334",
background_color: "#FBF6F1",
display: "standalone",
start_url: "/",
icons: [
{ src: "/pwa-192.png", sizes: "192x192", type: "image/png" },
{ src: "/pwa-512.png", sizes: "512x512", type: "image/png" },
{
src: "/pwa-512-maskable.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
workbox: {
// Take control on first load so the conversion's core fetch is cached
// immediately. Updates still wait for the user (skipWaiting stays off).
clientsClaim: true,
// Precache the small app shell (html/js/css/fonts/icons) for offline reload.
globPatterns: ["**/*.{js,css,html,woff,woff2,png,svg,ico}"],
// Do NOT precache the 31MB ffmpeg core; cache it at runtime on first use.
globIgnores: ["**/ffmpeg/**"],
runtimeCaching: [
{
urlPattern: ({ url }) => url.pathname.includes("/ffmpeg/"),
handler: "CacheFirst",
options: {
cacheName: "ffmpeg-core",
cacheableResponse: { statuses: [0, 200] },
expiration: { maxEntries: 4, maxAgeSeconds: 60 * 60 * 24 * 60 },
},
},
],
},
devOptions: { enabled: false },
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
// ffmpeg's worker + wasm are loaded at runtime via ?url assets; don't pre-bundle.
optimizeDeps: { exclude: ["@ffmpeg/ffmpeg", "@ffmpeg/util"] },
});