vite.config.ts 5.8 KB

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