vite.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. import { defineConfig } from "vite";
  3. import react from "@vitejs/plugin-react";
  4. import { VitePWA } from "vite-plugin-pwa";
  5. export default defineConfig(({ mode }) => ({
  6. build: {
  7. outDir: "build",
  8. assetsDir: "static/media",
  9. sourcemap: true,
  10. },
  11. server: {
  12. port: 3000,
  13. },
  14. plugins: [
  15. react(),
  16. VitePWA({
  17. registerType: "autoUpdate",
  18. // see registerSW.js imported by index.jsx
  19. injectRegister: null,
  20. strategies: "injectManifest",
  21. devOptions: {
  22. enabled: true,
  23. /* when using generateSW the PWA plugin will switch to classic */
  24. type: "module",
  25. navigateFallback: "index.html",
  26. },
  27. injectManifest: {
  28. globPatterns: ["**/*.{js,css,html,ico,png,svg,json}"],
  29. globIgnores: ["config.js"],
  30. manifestTransforms: [
  31. (entries) => ({
  32. manifest: entries.map((entry) =>
  33. // this matches the build step in the Makefile.
  34. // since ntfy needs the ability to serve another page on /index.html,
  35. // it's renamed and served from server.go as app.html as well.
  36. entry.url === "index.html"
  37. ? {
  38. ...entry,
  39. url: "app.html",
  40. }
  41. : entry
  42. ),
  43. }),
  44. ],
  45. },
  46. // The actual prod manifest is served from the go server, see server.go handleWebManifest.
  47. manifest: mode === "development" && {
  48. theme_color: "#317f6f",
  49. icons: [
  50. {
  51. src: "/static/images/pwa-192x192.png",
  52. sizes: "192x192",
  53. type: "image/png",
  54. },
  55. ],
  56. },
  57. }),
  58. ],
  59. }));