vite.config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { defineConfig } from "vite";
  2. import react from "@vitejs/plugin-react";
  3. import svgrPlugin from "vite-plugin-svgr";
  4. import { ViteEjsPlugin } from "vite-plugin-ejs";
  5. import { VitePWA } from "vite-plugin-pwa";
  6. import eslint from "vite-plugin-eslint";
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. build: {
  10. outDir: "build",
  11. rollupOptions: {
  12. output: {
  13. // Creating separate chunk for locales except for en and percentages.json so they
  14. // can be cached at runtime and not merged with
  15. // app precache. en.json and percentages.json are needed for first load
  16. // or fallback hence not clubbing with locales so first load followed by offline mode works fine. This is how CRA used to work too.
  17. manualChunks(id) {
  18. if (
  19. id.includes("src/locales") &&
  20. id.match(/en.json|percentages.json/) === null
  21. ) {
  22. const index = id.indexOf("locales/");
  23. // Taking the substring after "locales/"
  24. return `locales/${id.substring(index + 8)}`;
  25. }
  26. },
  27. },
  28. },
  29. sourcemap: true,
  30. },
  31. plugins: [
  32. react(),
  33. eslint(),
  34. svgrPlugin(),
  35. ViteEjsPlugin(),
  36. VitePWA({
  37. devOptions: {
  38. /* set this flag to true to enable in Development mode */
  39. enabled: false,
  40. },
  41. workbox: {
  42. // Don't push fonts and locales to app precache
  43. globIgnores: ["fonts.css", "**/locales/**"],
  44. runtimeCaching: [
  45. {
  46. urlPattern: new RegExp("/.+.(ttf|woff2|otf)"),
  47. handler: "CacheFirst",
  48. options: {
  49. cacheName: "fonts",
  50. expiration: {
  51. maxEntries: 50,
  52. maxAgeSeconds: 60 * 60 * 24 * 90, // <== 90 days
  53. },
  54. },
  55. },
  56. {
  57. urlPattern: new RegExp("fonts.css"),
  58. handler: "StaleWhileRevalidate",
  59. options: {
  60. cacheName: "fonts",
  61. expiration: {
  62. maxEntries: 50,
  63. },
  64. },
  65. },
  66. {
  67. urlPattern: new RegExp("locales/[^/]+.js"),
  68. handler: "CacheFirst",
  69. options: {
  70. cacheName: "locales",
  71. expiration: {
  72. maxEntries: 50,
  73. maxAgeSeconds: 60 * 60 * 24 * 30, // <== 30 days
  74. },
  75. },
  76. },
  77. ],
  78. },
  79. manifest: {
  80. short_name: "Excalidraw",
  81. name: "Excalidraw",
  82. description:
  83. "Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them.",
  84. icons: [
  85. {
  86. src: "logo-180x180.png",
  87. sizes: "180x180",
  88. type: "image/png",
  89. },
  90. {
  91. src: "apple-touch-icon.png",
  92. type: "image/png",
  93. sizes: "256x256",
  94. },
  95. ],
  96. start_url: "/",
  97. display: "standalone",
  98. theme_color: "#121212",
  99. background_color: "#ffffff",
  100. file_handlers: [
  101. {
  102. action: "/",
  103. accept: {
  104. "application/vnd.excalidraw+json": [".excalidraw"],
  105. },
  106. },
  107. ],
  108. share_target: {
  109. action: "/web-share-target",
  110. method: "POST",
  111. enctype: "multipart/form-data",
  112. params: {
  113. files: [
  114. {
  115. name: "file",
  116. accept: [
  117. "application/vnd.excalidraw+json",
  118. "application/json",
  119. ".excalidraw",
  120. ],
  121. },
  122. ],
  123. },
  124. },
  125. screenshots: [
  126. {
  127. src: "/screenshots/virtual-whiteboard.png",
  128. type: "image/png",
  129. sizes: "462x945",
  130. },
  131. {
  132. src: "/screenshots/wireframe.png",
  133. type: "image/png",
  134. sizes: "462x945",
  135. },
  136. {
  137. src: "/screenshots/illustration.png",
  138. type: "image/png",
  139. sizes: "462x945",
  140. },
  141. {
  142. src: "/screenshots/shapes.png",
  143. type: "image/png",
  144. sizes: "462x945",
  145. },
  146. {
  147. src: "/screenshots/collaboration.png",
  148. type: "image/png",
  149. sizes: "462x945",
  150. },
  151. {
  152. src: "/screenshots/export.png",
  153. type: "image/png",
  154. sizes: "462x945",
  155. },
  156. ],
  157. },
  158. }),
  159. ],
  160. publicDir: "./public",
  161. });