vite.config.ts 5.1 KB

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