vite.config.ts 7.4 KB

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