vite.config.ts 5.9 KB

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