vite.config.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. devOptions: {
  55. /* set this flag to true to enable in Development mode */
  56. enabled: false,
  57. },
  58. workbox: {
  59. // Don't push fonts and locales to app precache
  60. globIgnores: ["fonts.css", "**/locales/**"],
  61. runtimeCaching: [
  62. {
  63. urlPattern: new RegExp("/.+.(ttf|woff2|otf)"),
  64. handler: "CacheFirst",
  65. options: {
  66. cacheName: "fonts",
  67. expiration: {
  68. maxEntries: 50,
  69. maxAgeSeconds: 60 * 60 * 24 * 90, // <== 90 days
  70. },
  71. },
  72. },
  73. {
  74. urlPattern: new RegExp("fonts.css"),
  75. handler: "StaleWhileRevalidate",
  76. options: {
  77. cacheName: "fonts",
  78. expiration: {
  79. maxEntries: 50,
  80. },
  81. },
  82. },
  83. {
  84. urlPattern: new RegExp("locales/[^/]+.js"),
  85. handler: "CacheFirst",
  86. options: {
  87. cacheName: "locales",
  88. expiration: {
  89. maxEntries: 50,
  90. maxAgeSeconds: 60 * 60 * 24 * 30, // <== 30 days
  91. },
  92. },
  93. },
  94. ],
  95. },
  96. manifest: {
  97. short_name: "Excalidraw",
  98. name: "Excalidraw",
  99. description:
  100. "Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them.",
  101. icons: [
  102. {
  103. src: "logo-180x180.png",
  104. sizes: "180x180",
  105. type: "image/png",
  106. },
  107. {
  108. src: "apple-touch-icon.png",
  109. type: "image/png",
  110. sizes: "256x256",
  111. },
  112. ],
  113. start_url: "/",
  114. display: "standalone",
  115. theme_color: "#121212",
  116. background_color: "#ffffff",
  117. file_handlers: [
  118. {
  119. action: "/",
  120. accept: {
  121. "application/vnd.excalidraw+json": [".excalidraw"],
  122. },
  123. },
  124. ],
  125. share_target: {
  126. action: "/web-share-target",
  127. method: "POST",
  128. enctype: "multipart/form-data",
  129. params: {
  130. files: [
  131. {
  132. name: "file",
  133. accept: [
  134. "application/vnd.excalidraw+json",
  135. "application/json",
  136. ".excalidraw",
  137. ],
  138. },
  139. ],
  140. },
  141. },
  142. screenshots: [
  143. {
  144. src: "/screenshots/virtual-whiteboard.png",
  145. type: "image/png",
  146. sizes: "462x945",
  147. },
  148. {
  149. src: "/screenshots/wireframe.png",
  150. type: "image/png",
  151. sizes: "462x945",
  152. },
  153. {
  154. src: "/screenshots/illustration.png",
  155. type: "image/png",
  156. sizes: "462x945",
  157. },
  158. {
  159. src: "/screenshots/shapes.png",
  160. type: "image/png",
  161. sizes: "462x945",
  162. },
  163. {
  164. src: "/screenshots/collaboration.png",
  165. type: "image/png",
  166. sizes: "462x945",
  167. },
  168. {
  169. src: "/screenshots/export.png",
  170. type: "image/png",
  171. sizes: "462x945",
  172. },
  173. ],
  174. },
  175. }),
  176. ],
  177. publicDir: "./public",
  178. });