vite.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. injectRegister: "inline",
  19. strategies: "injectManifest",
  20. devOptions: {
  21. enabled: true,
  22. /* when using generateSW the PWA plugin will switch to classic */
  23. type: "module",
  24. navigateFallback: "index.html",
  25. },
  26. injectManifest: {
  27. globPatterns: ["**/*.{js,css,html,mp3,ico,png,svg,json}"],
  28. globIgnores: ["config.js"],
  29. manifestTransforms: [
  30. (entries) => ({
  31. manifest: entries.map((entry) =>
  32. // this matches the build step in the Makefile.
  33. // since ntfy needs the ability to serve another page on /index.html,
  34. // it's renamed and served from server.go as app.html as well.
  35. entry.url === "index.html"
  36. ? {
  37. ...entry,
  38. url: "app.html",
  39. }
  40. : entry
  41. ),
  42. }),
  43. ],
  44. },
  45. // The actual prod manifest is served from the go server, see server.go handleWebManifest.
  46. manifest: mode === "development" && {
  47. theme_color: "#317f6f",
  48. icons: [
  49. {
  50. src: "/static/images/pwa-192x192.png",
  51. sizes: "192x192",
  52. type: "image/png",
  53. },
  54. ],
  55. },
  56. }),
  57. ],
  58. }));