vite.config.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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: [
  119. "../hoppscotch-common/src/components",
  120. "../hoppscotch-ui/src/components",
  121. ],
  122. directoryAsNamespace: true,
  123. resolvers: [
  124. IconResolver({
  125. prefix: "icon",
  126. customCollections: ["hopp", "auth", "brands"],
  127. }),
  128. (compName: string) => {
  129. if (compName.startsWith("Hopp"))
  130. return { name: compName, from: "@hoppscotch/ui" }
  131. else return undefined
  132. },
  133. ],
  134. types: [
  135. {
  136. from: "vue-tippy",
  137. names: ["Tippy"],
  138. },
  139. ],
  140. }),
  141. Icons({
  142. compiler: "vue3",
  143. customCollections: {
  144. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  145. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  146. brands: FileSystemIconLoader(
  147. "../hoppscotch-common/assets/icons/brands"
  148. ),
  149. },
  150. }),
  151. VitePWA({
  152. useCredentials: true,
  153. manifest: {
  154. name: APP_INFO.name,
  155. short_name: APP_INFO.name,
  156. description: APP_INFO.shortDescription,
  157. start_url: "/?source=pwa",
  158. id: "/?source=pwa",
  159. protocol_handlers: [
  160. {
  161. protocol: "web+hoppscotch",
  162. url: "/%s",
  163. },
  164. {
  165. protocol: "web+hopp",
  166. url: "/%s",
  167. },
  168. ],
  169. background_color: APP_INFO.app.background,
  170. theme_color: APP_INFO.app.background,
  171. icons: [
  172. {
  173. src: "/icons/pwa-16x16.png",
  174. sizes: "16x16",
  175. type: "image/png",
  176. },
  177. {
  178. src: "/icons/pwa-32x32.png",
  179. sizes: "32x32",
  180. type: "image/png",
  181. },
  182. {
  183. src: "/icons/pwa-128x128.png",
  184. sizes: "128x128",
  185. type: "image/png",
  186. },
  187. {
  188. src: "/icons/pwa-192x192.png",
  189. sizes: "192x192",
  190. type: "image/png",
  191. },
  192. {
  193. src: "/icons/pwa-256x256.png",
  194. sizes: "256x256",
  195. type: "image/png",
  196. },
  197. {
  198. src: "/icons/pwa-512x512.png",
  199. sizes: "512x512",
  200. type: "image/png",
  201. },
  202. {
  203. src: "/icons/pwa-1024x1024.png",
  204. sizes: "1024x1024",
  205. type: "image/png",
  206. },
  207. ],
  208. },
  209. registerType: "prompt",
  210. workbox: {
  211. cleanupOutdatedCaches: true,
  212. maximumFileSizeToCacheInBytes: 4194304,
  213. navigateFallbackDenylist: [
  214. /robots.txt/,
  215. /sitemap.xml/,
  216. /discord/,
  217. /telegram/,
  218. /beta/,
  219. /careers/,
  220. /newsletter/,
  221. /twitter/,
  222. /github/,
  223. /announcements/,
  224. /admin/,
  225. /backend/,
  226. ],
  227. },
  228. }),
  229. Unfonts({
  230. fontsource: {
  231. families: [
  232. {
  233. name: "Inter Variable",
  234. variables: ["variable-full"],
  235. },
  236. {
  237. name: "Material Symbols Rounded Variable",
  238. variables: ["variable-full"],
  239. },
  240. {
  241. name: "Roboto Mono Variable",
  242. variables: ["variable-full"],
  243. },
  244. ],
  245. },
  246. }),
  247. legacy({
  248. modernPolyfills: ["es.string.replace-all"],
  249. renderLegacyChunks: false,
  250. }),
  251. process.env.HOPP_ALLOW_RUNTIME_ENV
  252. ? ImportMetaEnv.vite({
  253. example: "../../.env.example",
  254. env: "../../.env",
  255. })
  256. : [],
  257. ],
  258. })