vite.config.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. "@api": path.resolve(__dirname, "./src/api"),
  73. "@lib": path.resolve(__dirname, "./src/lib"),
  74. stream: "stream-browserify",
  75. util: "util",
  76. querystring: "qs",
  77. },
  78. dedupe: ["vue"],
  79. },
  80. plugins: [
  81. Inspect(), // go to url -> /__inspect
  82. HtmlConfig({
  83. metas: META_TAGS(ENV),
  84. }),
  85. Vue(),
  86. Pages({
  87. routeStyle: "nuxt",
  88. dirs: "../hoppscotch-common/src/pages",
  89. importMode: "async",
  90. onRoutesGenerated(routes) {
  91. generateSitemap({
  92. routes,
  93. nuxtStyle: true,
  94. allowRobots: true,
  95. dest: ".sitemap-gen",
  96. hostname: ENV.VITE_BASE_URL,
  97. })
  98. },
  99. }),
  100. StaticCopy({
  101. targets: [
  102. {
  103. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  104. dest: normalizePath(path.resolve(__dirname, "./dist")),
  105. },
  106. ],
  107. }),
  108. Layouts({
  109. layoutsDirs: "../hoppscotch-common/src/layouts",
  110. defaultLayout: "default",
  111. }),
  112. VueI18n({
  113. runtimeOnly: false,
  114. compositionOnly: true,
  115. include: [path.resolve(__dirname, "locales")],
  116. }),
  117. Components({
  118. dts: "../hoppscotch-common/src/components.d.ts",
  119. dirs: ["../hoppscotch-common/src/components"],
  120. directoryAsNamespace: true,
  121. resolvers: [
  122. IconResolver({
  123. prefix: "icon",
  124. customCollections: ["hopp", "auth", "brands"],
  125. }),
  126. (compName: string) => {
  127. if (compName.startsWith("Hopp"))
  128. return { name: compName, from: "@hoppscotch/ui" }
  129. else return undefined
  130. },
  131. ],
  132. types: [
  133. {
  134. from: "vue-tippy",
  135. names: ["Tippy"],
  136. },
  137. ],
  138. }),
  139. Icons({
  140. compiler: "vue3",
  141. customCollections: {
  142. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  143. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  144. brands: FileSystemIconLoader(
  145. "../hoppscotch-common/assets/icons/brands"
  146. ),
  147. },
  148. }),
  149. VitePWA({
  150. useCredentials: true,
  151. manifest: {
  152. name: APP_INFO.name,
  153. short_name: APP_INFO.name,
  154. description: APP_INFO.shortDescription,
  155. start_url: "/?source=pwa",
  156. id: "/?source=pwa",
  157. protocol_handlers: [
  158. {
  159. protocol: "web+hoppscotch",
  160. url: "/%s",
  161. },
  162. {
  163. protocol: "web+hopp",
  164. url: "/%s",
  165. },
  166. ],
  167. background_color: APP_INFO.app.background,
  168. theme_color: APP_INFO.app.background,
  169. icons: [
  170. {
  171. src: "/icons/pwa-16x16.png",
  172. sizes: "16x16",
  173. type: "image/png",
  174. },
  175. {
  176. src: "/icons/pwa-32x32.png",
  177. sizes: "32x32",
  178. type: "image/png",
  179. },
  180. {
  181. src: "/icons/pwa-128x128.png",
  182. sizes: "128x128",
  183. type: "image/png",
  184. },
  185. {
  186. src: "/icons/pwa-192x192.png",
  187. sizes: "192x192",
  188. type: "image/png",
  189. },
  190. {
  191. src: "/icons/pwa-256x256.png",
  192. sizes: "256x256",
  193. type: "image/png",
  194. },
  195. {
  196. src: "/icons/pwa-512x512.png",
  197. sizes: "512x512",
  198. type: "image/png",
  199. },
  200. {
  201. src: "/icons/pwa-1024x1024.png",
  202. sizes: "1024x1024",
  203. type: "image/png",
  204. },
  205. ],
  206. },
  207. registerType: "prompt",
  208. workbox: {
  209. cleanupOutdatedCaches: true,
  210. maximumFileSizeToCacheInBytes: 10485760,
  211. navigateFallbackDenylist: [
  212. /robots.txt/,
  213. /sitemap.xml/,
  214. /discord/,
  215. /telegram/,
  216. /beta/,
  217. /careers/,
  218. /newsletter/,
  219. /twitter/,
  220. /github/,
  221. /announcements/,
  222. /admin/,
  223. /backend/,
  224. ],
  225. },
  226. }),
  227. Unfonts({
  228. fontsource: {
  229. families: [
  230. {
  231. name: "Inter Variable",
  232. variables: ["variable-full"],
  233. },
  234. {
  235. name: "Material Symbols Rounded Variable",
  236. variables: ["variable-full"],
  237. },
  238. {
  239. name: "Roboto Mono Variable",
  240. variables: ["variable-full"],
  241. },
  242. ],
  243. },
  244. }),
  245. legacy({
  246. modernPolyfills: ["es.string.replace-all"],
  247. renderLegacyChunks: false,
  248. }),
  249. process.env.HOPP_ALLOW_RUNTIME_ENV
  250. ? ImportMetaEnv.vite({
  251. example: "../../.env.example",
  252. env: "../../.env",
  253. })
  254. : [],
  255. ],
  256. css: {
  257. preprocessorOptions: {
  258. scss: {
  259. api: "modern",
  260. },
  261. },
  262. },
  263. })