vite.config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. "./src/components"
  110. ],
  111. directoryAsNamespace: true,
  112. resolvers: [
  113. IconResolver({
  114. prefix: "icon",
  115. customCollections: ["hopp", "auth", "brands"],
  116. }),
  117. (compName: string) => {
  118. if (compName.startsWith("Hopp"))
  119. return { name: compName, from: "@hoppscotch/ui" }
  120. else return undefined
  121. },
  122. ],
  123. types: [
  124. {
  125. from: "vue-tippy",
  126. names: ["Tippy"],
  127. },
  128. ],
  129. }),
  130. Icons({
  131. compiler: "vue3",
  132. customCollections: {
  133. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  134. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  135. brands: FileSystemIconLoader(
  136. "../hoppscotch-common/assets/icons/brands"
  137. ),
  138. },
  139. }),
  140. VitePWA({
  141. manifest: {
  142. name: APP_INFO.name,
  143. short_name: APP_INFO.name,
  144. description: APP_INFO.shortDescription,
  145. start_url: "/?source=pwa",
  146. background_color: APP_INFO.app.background,
  147. theme_color: APP_INFO.app.background,
  148. icons: [
  149. {
  150. src: "/icon.png",
  151. sizes: "512x512",
  152. type: "image/png",
  153. purpose: "any maskable",
  154. },
  155. {
  156. src: "/logo.svg",
  157. sizes: "48x48 72x72 96x96 128x128 256x256 512x512",
  158. type: "image/svg+xml",
  159. purpose: "any maskable",
  160. },
  161. ],
  162. },
  163. registerType: "prompt",
  164. workbox: {
  165. cleanupOutdatedCaches: true,
  166. maximumFileSizeToCacheInBytes: 4194304,
  167. navigateFallbackDenylist: [
  168. /robots.txt/,
  169. /sitemap.xml/,
  170. /discord/,
  171. /telegram/,
  172. /beta/,
  173. /careers/,
  174. /newsletter/,
  175. /twitter/,
  176. /github/,
  177. /announcements/,
  178. ],
  179. },
  180. }),
  181. Unfonts({
  182. fontsource: {
  183. families: [
  184. {
  185. name: "Inter Variable",
  186. variables: ["variable-full"],
  187. },
  188. {
  189. name: "Material Symbols Rounded Variable",
  190. variables: ["variable-full"],
  191. },
  192. {
  193. name: "Roboto Mono Variable",
  194. variables: ["variable-full"],
  195. },
  196. ],
  197. },
  198. }),
  199. legacy({
  200. modernPolyfills: ["es.string.replace-all"],
  201. renderLegacyChunks: false,
  202. }),
  203. ],
  204. })