vite.config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. background_color: APP_INFO.app.background,
  152. theme_color: APP_INFO.app.background,
  153. icons: [
  154. {
  155. src: "/icon.png",
  156. sizes: "512x512",
  157. type: "image/png",
  158. purpose: "any maskable",
  159. },
  160. {
  161. src: "/logo.svg",
  162. sizes: "48x48 72x72 96x96 128x128 256x256 512x512",
  163. type: "image/svg+xml",
  164. purpose: "any maskable",
  165. },
  166. ],
  167. },
  168. registerType: "prompt",
  169. workbox: {
  170. cleanupOutdatedCaches: true,
  171. maximumFileSizeToCacheInBytes: 4194304,
  172. navigateFallbackDenylist: [
  173. /robots.txt/,
  174. /sitemap.xml/,
  175. /discord/,
  176. /telegram/,
  177. /beta/,
  178. /careers/,
  179. /newsletter/,
  180. /twitter/,
  181. /github/,
  182. /announcements/,
  183. ],
  184. },
  185. }),
  186. VitePluginFonts({
  187. google: {
  188. families: [
  189. "Inter:wght@400;500;600;700;800",
  190. "Roboto+Mono:wght@400;500",
  191. "Material+Icons",
  192. ],
  193. },
  194. }),
  195. legacy({
  196. modernPolyfills: ["es.string.replace-all"],
  197. renderLegacyChunks: false,
  198. }),
  199. ],
  200. })