vite.config.ts 5.0 KB

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