vite.config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. return ((generateSitemap as any) as typeof generateSitemap)({
  81. routes,
  82. nuxtStyle: true,
  83. allowRobots: true,
  84. dest: ".sitemap-gen",
  85. hostname: ENV.VITE_BASE_URL,
  86. })
  87. },
  88. }),
  89. StaticCopy({
  90. targets: [
  91. {
  92. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  93. dest: normalizePath(path.resolve(__dirname, "./dist")),
  94. },
  95. ],
  96. }),
  97. Layouts({
  98. layoutsDirs: "../hoppscotch-common/src/layouts",
  99. defaultLayout: "default",
  100. }),
  101. VueI18n({
  102. runtimeOnly: false,
  103. compositionOnly: true,
  104. include: [path.resolve(__dirname, "locales")],
  105. }),
  106. WindiCSS({
  107. root: path.resolve(__dirname, "../hoppscotch-common"),
  108. }),
  109. Components({
  110. dts: "../hoppscotch-common/src/components.d.ts",
  111. dirs: [
  112. "../hoppscotch-common/src/components",
  113. "../hoppscotch-ui/src/components",
  114. ],
  115. directoryAsNamespace: true,
  116. resolvers: [
  117. IconResolver({
  118. prefix: "icon",
  119. customCollections: ["hopp", "auth", "brands"],
  120. }),
  121. (compName: string) => {
  122. if (compName.startsWith("Hopp"))
  123. return { name: compName, from: "@hoppscotch/ui" }
  124. else return undefined
  125. },
  126. ],
  127. types: [
  128. {
  129. from: "vue-tippy",
  130. names: ["Tippy"],
  131. },
  132. ],
  133. }),
  134. Icons({
  135. compiler: "vue3",
  136. customCollections: {
  137. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  138. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  139. brands: FileSystemIconLoader(
  140. "../hoppscotch-common/assets/icons/brands"
  141. ),
  142. },
  143. }),
  144. VitePWA({
  145. manifest: {
  146. name: APP_INFO.name,
  147. short_name: APP_INFO.name,
  148. description: APP_INFO.shortDescription,
  149. start_url: "/?source=pwa",
  150. background_color: APP_INFO.app.background,
  151. theme_color: APP_INFO.app.background,
  152. icons: [
  153. {
  154. src: "/icon.png",
  155. sizes: "512x512",
  156. type: "image/png",
  157. purpose: "any maskable",
  158. },
  159. {
  160. src: "/logo.svg",
  161. sizes: "48x48 72x72 96x96 128x128 256x256 512x512",
  162. type: "image/svg+xml",
  163. purpose: "any maskable",
  164. },
  165. ],
  166. },
  167. registerType: "prompt",
  168. workbox: {
  169. cleanupOutdatedCaches: true,
  170. maximumFileSizeToCacheInBytes: 4194304,
  171. navigateFallbackDenylist: [
  172. /robots.txt/,
  173. /sitemap.xml/,
  174. /discord/,
  175. /telegram/,
  176. /beta/,
  177. /careers/,
  178. /newsletter/,
  179. /twitter/,
  180. /github/,
  181. /announcements/,
  182. ],
  183. },
  184. }),
  185. VitePluginFonts({
  186. google: {
  187. families: [
  188. "Inter:wght@400;500;600;700;800",
  189. "Roboto+Mono:wght@400;500",
  190. "Material+Icons",
  191. ],
  192. },
  193. }),
  194. legacy({
  195. modernPolyfills: ["es.string.replace-all"],
  196. renderLegacyChunks: false,
  197. }),
  198. ],
  199. })