vite.config.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. },
  39. resolve: {
  40. alias: {
  41. // TODO: Maybe leave ~ only for individual apps and not use on common
  42. "~": path.resolve(__dirname, "../hoppscotch-common/src"),
  43. "@hoppscotch/common": "@hoppscotch/common/src",
  44. "@composables": path.resolve(
  45. __dirname,
  46. "../hoppscotch-common/src/composables"
  47. ),
  48. "@modules": path.resolve(__dirname, "../hoppscotch-common/src/modules"),
  49. "@components": path.resolve(
  50. __dirname,
  51. "../hoppscotch-common/src/components"
  52. ),
  53. "@helpers": path.resolve(__dirname, "../hoppscotch-common/src/helpers"),
  54. "@functional": path.resolve(
  55. __dirname,
  56. "../hoppscotch-common/src/helpers/functional"
  57. ),
  58. "@workers": path.resolve(__dirname, "../hoppscotch-common/src/workers"),
  59. stream: "stream-browserify",
  60. util: "util",
  61. },
  62. dedupe: ["vue"],
  63. },
  64. plugins: [
  65. Inspect(), // go to url -> /__inspect
  66. HtmlConfig({
  67. metas: META_TAGS(ENV),
  68. }),
  69. Vue(),
  70. Pages({
  71. routeStyle: "nuxt",
  72. dirs: "../hoppscotch-common/src/pages",
  73. importMode: "async",
  74. onRoutesGenerated(routes) {
  75. // HACK: See: https://github.com/jbaubree/vite-plugin-pages-sitemap/issues/173
  76. return ((generateSitemap as any).default as typeof generateSitemap)({
  77. routes,
  78. nuxtStyle: true,
  79. allowRobots: true,
  80. dest: ".sitemap-gen",
  81. hostname: ENV.VITE_BASE_URL,
  82. })
  83. },
  84. }),
  85. StaticCopy({
  86. targets: [
  87. {
  88. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  89. dest: normalizePath(path.resolve(__dirname, "./dist")),
  90. },
  91. ],
  92. }),
  93. Layouts({
  94. layoutsDirs: "../hoppscotch-common/src/layouts",
  95. defaultLayout: "default",
  96. }),
  97. VueI18n({
  98. runtimeOnly: false,
  99. compositionOnly: true,
  100. include: [path.resolve(__dirname, "locales")],
  101. }),
  102. WindiCSS({
  103. root: path.resolve(__dirname, "../hoppscotch-common"),
  104. }),
  105. Components({
  106. dts: "../hoppscotch-common/src/components.d.ts",
  107. dirs: [
  108. "../hoppscotch-common/src/components",
  109. "../hoppscotch-ui/src/components",
  110. ],
  111. directoryAsNamespace: true,
  112. resolvers: [
  113. IconResolver({
  114. prefix: "icon",
  115. customCollections: ["hopp", "auth", "brands"],
  116. }),
  117. ],
  118. types: [
  119. {
  120. from: "vue-tippy",
  121. names: ["Tippy"],
  122. },
  123. ],
  124. }),
  125. Icons({
  126. compiler: "vue3",
  127. customCollections: {
  128. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  129. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  130. brands: FileSystemIconLoader(
  131. "../hoppscotch-common/assets/icons/brands"
  132. ),
  133. },
  134. }),
  135. VitePWA({
  136. manifest: {
  137. name: APP_INFO.name,
  138. short_name: APP_INFO.name,
  139. description: APP_INFO.shortDescription,
  140. start_url: "/?source=pwa",
  141. background_color: APP_INFO.app.background,
  142. theme_color: APP_INFO.app.background,
  143. icons: [
  144. {
  145. src: "/icon.png",
  146. sizes: "512x512",
  147. type: "image/png",
  148. purpose: "any maskable",
  149. },
  150. {
  151. src: "/logo.svg",
  152. sizes: "48x48 72x72 96x96 128x128 256x256 512x512",
  153. type: "image/svg+xml",
  154. purpose: "any maskable",
  155. },
  156. ],
  157. },
  158. registerType: "prompt",
  159. workbox: {
  160. cleanupOutdatedCaches: true,
  161. maximumFileSizeToCacheInBytes: 4194304,
  162. navigateFallbackDenylist: [
  163. /robots.txt/,
  164. /sitemap.xml/,
  165. /discord/,
  166. /telegram/,
  167. /beta/,
  168. /careers/,
  169. /newsletter/,
  170. /twitter/,
  171. /github/,
  172. /announcements/,
  173. ],
  174. },
  175. }),
  176. VitePluginFonts({
  177. google: {
  178. families: [
  179. "Inter:wght@400;500;600;700;800",
  180. "Roboto+Mono:wght@400;500",
  181. "Material+Icons",
  182. ],
  183. },
  184. }),
  185. legacy({
  186. modernPolyfills: ["es.string.replace-all"],
  187. renderLegacyChunks: false,
  188. }),
  189. ],
  190. })