vite.common.config.ts
⎇
Raw
1import { writeFileSync } from "node:fs";
2import type { VitePWAOptions } from "vite-plugin-pwa";
3
4export const pwaOptions: Partial<VitePWAOptions> = {
5 registerType: "autoUpdate",
6 workbox: {
7 globPatterns: ["**/*.{js,css,html,woff2}"],
8 navigateFallback: undefined,
9 //Leave media requests outside Workbox so native Range requests and cancellation are handled directly.
10 },
11 manifest: {
12 id: "/",
13 start_url: "/",
14 scope: "/",
15 name: "Pico Pixel Player",
16 short_name: "Pico Pixel Player",
17 description: "A directory based media player with offline functionality",
18 theme_color: "#3f4d4e",
19 screenshots: [
20 {
21 src: "/assets/screenshot-narrow.png",
22 form_factor: "narrow",
23 sizes: "600x800",
24 },
25 {
26 src: "/assets/screenshot-wide.png",
27 form_factor: "wide",
28 sizes: "1400x800",
29 },
30 ],
31 background_color: "#3f4d4e",
32 icons: [
33 {
34 src: "/assets/favicon-any.svg",
35 sizes: "any",
36 type: "image/svg+xml",
37 purpose: "any",
38 },
39 {
40 src: "/assets/favicon-maskable.svg",
41 sizes: "any",
42 type: "image/svg+xml",
43 purpose: "maskable",
44 },
45 {
46 //Android
47 src: "/assets/favicon-192x192.png",
48 sizes: "192x192",
49 type: "image/png",
50 purpose: "maskable",
51 },
52 {
53 //iOS
54 src: "/assets/favicon-180x180.png",
55 sizes: "180x180",
56 type: "image/png",
57 purpose: "maskable",
58 },
59 {
60 //Some store frontends require this
61 src: "/assets/favicon-512x512.png",
62 sizes: "512x512",
63 type: "image/png",
64 purpose: "any",
65 },
66 ],
67 display: "standalone",
68 display_override: ["standalone", "minimal-ui", "fullscreen"],
69 },
70};
71
72//a fresh id per build, shown in the header so a running client can be matched to a deployment
73export const hashPlugin = {
74 name: "build-hash",
75 buildStart() {
76 writeFileSync("src/build-info.ts", `export const BUILD_HASH = "${crypto.randomUUID().toUpperCase()}";\n`);
77 },
78};
79