vite.config.ts 7.1 KB

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