1import { defineConfig } from "vite";
2import react from "@vitejs/plugin-react";
3import { VitePWA } from "vite-plugin-pwa";
4import { execSync } from "child_process";
5
6// Fetch the last commit ID safely
7const getCommitHash = () => {
8 try {
9 return JSON.stringify(
10 execSync("git rev-parse --short HEAD").toString().trim()
11 );
12 } catch (e) {
13 console.log(e);
14 return JSON.stringify("unknown");
15 }
16};
17
18import { resolve, dirname } from "path";
19import { fileURLToPath } from "url";
20import pkg from "./package.json";
21
22const __filename = fileURLToPath(import.meta.url);
23const __dirname = dirname(__filename);
24
25// https://vite.dev/config/
26export default defineConfig({
27 define: {
28 __APP_VERSION__: JSON.stringify(pkg.version),
29 __APP_GIT_HASH__: getCommitHash(),
30 },
31 resolve: {
32 alias: {
33 "@": resolve(__dirname, "./src"),
34 },
35 },
36 plugins: [
37 react(),
38 // https://www.youtube.com/watch?v=YSGLw4T8BgQ
39 // https://alexop.dev/posts/create-pwa-vue3-vite-4-steps/
40 VitePWA({
41 registerType: "autoUpdate",
42 manifest: {
43 name: "panku",
44 short_name: "panku",
45 description: "split and share bills",
46 theme_color: "#ffffff",
47 icons: [
48 {
49 src: "pwa-64x64.png",
50 sizes: "64x64",
51 type: "image/png",
52 },
53 {
54 src: "pwa-192x192.png",
55 sizes: "192x192",
56 type: "image/png",
57 },
58 {
59 src: "pwa-512x512.png",
60 sizes: "512x512",
61 type: "image/png",
62 },
63 {
64 src: "maskable-icon-512x512.png",
65 sizes: "512x512",
66 type: "image/png",
67 purpose: "maskable",
68 },
69 ],
70 },
71 workbox: {
72 // prevent caching of any .bin file requests
73 navigateFallbackDenylist: [/^\/*.bin/],
74 },
75 // devOptions: {
76 // enabled: true,
77 // },
78 }),
79 ],
80});