vite.config.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { defineConfig, loadEnv, normalizePath } from "vite"
  2. import { APP_INFO, META_TAGS } from "./meta"
  3. import { viteStaticCopy as StaticCopy } from "vite-plugin-static-copy"
  4. import generateSitemap from "vite-plugin-pages-sitemap"
  5. import HtmlConfig from "vite-plugin-html-config"
  6. import Vue from "@vitejs/plugin-vue"
  7. import VueI18n from "@intlify/vite-plugin-vue-i18n"
  8. import Components from "unplugin-vue-components/vite"
  9. import Icons from "unplugin-icons/vite"
  10. import Inspect from "vite-plugin-inspect"
  11. import WindiCSS from "vite-plugin-windicss"
  12. import { VitePWA } from "vite-plugin-pwa"
  13. import Pages from "vite-plugin-pages"
  14. import Layouts from "vite-plugin-vue-layouts"
  15. import IconResolver from "unplugin-icons/resolver"
  16. import { FileSystemIconLoader } from "unplugin-icons/loaders"
  17. import * as path from "path"
  18. import { VitePluginFonts } from "vite-plugin-fonts"
  19. import legacy from "@vitejs/plugin-legacy"
  20. const ENV = loadEnv("development", path.resolve(__dirname, "../../"))
  21. export default defineConfig({
  22. envDir: path.resolve(__dirname, "../../"),
  23. // TODO: Migrate @hoppscotch/data to full ESM
  24. define: {
  25. // For 'util' polyfill required by dep of '@apidevtools/swagger-parser'
  26. "process.env": {},
  27. },
  28. server: {
  29. port: 3000,
  30. },
  31. preview: {
  32. port: 3000,
  33. },
  34. publicDir: path.resolve(__dirname, "../hoppscotch-common/public"),
  35. build: {
  36. sourcemap: true,
  37. emptyOutDir: true,
  38. rollupOptions: {
  39. maxParallelFileOps: 2,
  40. },
  41. },
  42. resolve: {
  43. alias: {
  44. // TODO: Maybe leave ~ only for individual apps and not use on common
  45. "~": path.resolve(__dirname, "../hoppscotch-common/src"),
  46. "@hoppscotch/common": "@hoppscotch/common/src",
  47. "@composables": path.resolve(
  48. __dirname,
  49. "../hoppscotch-common/src/composables"
  50. ),
  51. "@modules": path.resolve(__dirname, "../hoppscotch-common/src/modules"),
  52. "@components": path.resolve(
  53. __dirname,
  54. "../hoppscotch-common/src/components"
  55. ),
  56. "@helpers": path.resolve(__dirname, "../hoppscotch-common/src/helpers"),
  57. "@functional": path.resolve(
  58. __dirname,
  59. "../hoppscotch-common/src/helpers/functional"
  60. ),
  61. "@workers": path.resolve(__dirname, "../hoppscotch-common/src/workers"),
  62. "@platform": path.resolve(__dirname, "./src/platform"),
  63. "@lib": path.resolve(__dirname, "./src/lib"),
  64. stream: "stream-browserify",
  65. util: "util",
  66. },
  67. dedupe: ["vue"],
  68. },
  69. plugins: [
  70. Inspect(), // go to url -> /__inspect
  71. HtmlConfig({
  72. metas: META_TAGS(ENV),
  73. }),
  74. Vue(),
  75. Pages({
  76. routeStyle: "nuxt",
  77. dirs: "../hoppscotch-common/src/pages",
  78. importMode: "async",
  79. onRoutesGenerated(routes) {
  80. // HACK: See: https://github.com/jbaubree/vite-plugin-pages-sitemap/issues/173
  81. return ((generateSitemap as any).default as typeof generateSitemap)({
  82. routes,
  83. nuxtStyle: true,
  84. allowRobots: true,
  85. dest: ".sitemap-gen",
  86. hostname: ENV.VITE_BASE_URL,
  87. })
  88. },
  89. }),
  90. StaticCopy({
  91. targets: [
  92. {
  93. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  94. dest: normalizePath(path.resolve(__dirname, "./dist")),
  95. },
  96. ],
  97. }),
  98. Layouts({
  99. layoutsDirs: "../hoppscotch-common/src/layouts",
  100. defaultLayout: "default",
  101. }),
  102. VueI18n({
  103. runtimeOnly: false,
  104. compositionOnly: true,
  105. include: [path.resolve(__dirname, "locales")],
  106. }),
  107. WindiCSS({
  108. root: path.resolve(__dirname, "../hoppscotch-common"),
  109. }),
  110. Components({
  111. dts: "../hoppscotch-common/src/components.d.ts",
  112. dirs: [
  113. "../hoppscotch-common/src/components",
  114. "../hoppscotch-ui/src/components",
  115. ],
  116. directoryAsNamespace: true,
  117. resolvers: [
  118. IconResolver({
  119. prefix: "icon",
  120. customCollections: ["hopp", "auth", "brands"],
  121. }),
  122. (compName: string) => {
  123. if (compName.startsWith("Hopp"))
  124. return { name: compName, from: "@hoppscotch/ui" }
  125. else return undefined
  126. },
  127. ],
  128. types: [
  129. {
  130. from: "vue-tippy",
  131. names: ["Tippy"],
  132. },
  133. ],
  134. }),
  135. Icons({
  136. compiler: "vue3",
  137. customCollections: {
  138. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  139. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  140. brands: FileSystemIconLoader(
  141. "../hoppscotch-common/assets/icons/brands"
  142. ),
  143. },
  144. }),
  145. VitePWA({
  146. manifest: {
  147. name: APP_INFO.name,
  148. short_name: APP_INFO.name,
  149. description: APP_INFO.shortDescription,
  150. start_url: "/?source=pwa",
  151. id: "/?source=pwa",
  152. protocol_handlers: [
  153. {
  154. protocol: "web+hoppscotch",
  155. url: "/%s",
  156. },
  157. {
  158. protocol: "web+hopp",
  159. url: "/%s",
  160. },
  161. ],
  162. background_color: APP_INFO.app.background,
  163. theme_color: APP_INFO.app.background,
  164. icons: [
  165. {
  166. src: "/icons/pwa-16x16.png",
  167. sizes: "16x16",
  168. type: "image/png",
  169. },
  170. {
  171. src: "/icons/pwa-32x32.png",
  172. sizes: "32x32",
  173. type: "image/png",
  174. },
  175. {
  176. src: "/icons/pwa-128x128.png",
  177. sizes: "128x128",
  178. type: "image/png",
  179. },
  180. {
  181. src: "/icons/pwa-192x192.png",
  182. sizes: "192x192",
  183. type: "image/png",
  184. },
  185. {
  186. src: "/icons/pwa-256x256.png",
  187. sizes: "256x256",
  188. type: "image/png",
  189. },
  190. {
  191. src: "/icons/pwa-512x512.png",
  192. sizes: "512x512",
  193. type: "image/png",
  194. },
  195. {
  196. src: "/icons/pwa-1024x1024.png",
  197. sizes: "1024x1024",
  198. type: "image/png",
  199. },
  200. ],
  201. },
  202. registerType: "prompt",
  203. workbox: {
  204. cleanupOutdatedCaches: true,
  205. maximumFileSizeToCacheInBytes: 4194304,
  206. navigateFallbackDenylist: [
  207. /robots.txt/,
  208. /sitemap.xml/,
  209. /discord/,
  210. /telegram/,
  211. /beta/,
  212. /careers/,
  213. /newsletter/,
  214. /twitter/,
  215. /github/,
  216. /announcements/,
  217. ],
  218. },
  219. }),
  220. VitePluginFonts({
  221. google: {
  222. families: [
  223. "Inter:wght@400;500;600;700;800",
  224. "Roboto+Mono:wght@400;500",
  225. "Material+Icons",
  226. ],
  227. },
  228. }),
  229. legacy({
  230. modernPolyfills: ["es.string.replace-all"],
  231. renderLegacyChunks: false,
  232. }),
  233. ],
  234. })