vite.config.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. "process.platform": '"browser"',
  29. },
  30. server: {
  31. port: 3000,
  32. },
  33. preview: {
  34. port: 3000,
  35. },
  36. publicDir: path.resolve(__dirname, "../hoppscotch-common/public"),
  37. build: {
  38. sourcemap: true,
  39. emptyOutDir: true,
  40. rollupOptions: {
  41. maxParallelFileOps: 2,
  42. },
  43. },
  44. resolve: {
  45. alias: {
  46. "tailwind.config.cjs": path.resolve(
  47. __dirname,
  48. "../hoppscotch-common/tailwind.config.cjs"
  49. ),
  50. "postcss.config.cjs": path.resolve(
  51. __dirname,
  52. "../hoppscotch-common/postcss.config.cjs"
  53. ),
  54. // TODO: Maybe leave ~ only for individual apps and not use on common
  55. "~": path.resolve(__dirname, "../hoppscotch-common/src"),
  56. "@hoppscotch/common": "@hoppscotch/common/src",
  57. "@composables": path.resolve(
  58. __dirname,
  59. "../hoppscotch-common/src/composables"
  60. ),
  61. "@modules": path.resolve(__dirname, "../hoppscotch-common/src/modules"),
  62. "@components": path.resolve(
  63. __dirname,
  64. "../hoppscotch-common/src/components"
  65. ),
  66. "@helpers": path.resolve(__dirname, "../hoppscotch-common/src/helpers"),
  67. "@functional": path.resolve(
  68. __dirname,
  69. "../hoppscotch-common/src/helpers/functional"
  70. ),
  71. "@workers": path.resolve(__dirname, "../hoppscotch-common/src/workers"),
  72. "@platform": path.resolve(__dirname, "./src/platform"),
  73. "@platform-components": path.resolve(__dirname, "./src/components"),
  74. "@api": path.resolve(__dirname, "./src/api"),
  75. "@lib": path.resolve(__dirname, "./src/lib"),
  76. stream: "stream-browserify",
  77. util: "util",
  78. querystring: "qs",
  79. },
  80. dedupe: ["vue"],
  81. },
  82. plugins: [
  83. Inspect(), // go to url -> /__inspect
  84. HtmlConfig({
  85. metas: META_TAGS(ENV),
  86. }),
  87. Vue(),
  88. Pages({
  89. routeStyle: "nuxt",
  90. dirs: ["../hoppscotch-common/src/pages", "./src/pages"],
  91. importMode: "async",
  92. onRoutesGenerated(routes) {
  93. generateSitemap({
  94. routes,
  95. nuxtStyle: true,
  96. allowRobots: true,
  97. dest: ".sitemap-gen",
  98. hostname: ENV.VITE_BASE_URL,
  99. })
  100. },
  101. }),
  102. StaticCopy({
  103. targets: [
  104. {
  105. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  106. dest: normalizePath(path.resolve(__dirname, "./dist")),
  107. },
  108. ],
  109. }),
  110. Layouts({
  111. layoutsDirs: "../hoppscotch-common/src/layouts",
  112. defaultLayout: "default",
  113. }),
  114. VueI18n({
  115. runtimeOnly: false,
  116. compositionOnly: true,
  117. include: [path.resolve(__dirname, "locales")],
  118. }),
  119. Components({
  120. dts: "../hoppscotch-common/src/components.d.ts",
  121. dirs: ["../hoppscotch-common/src/components"],
  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: 10485760,
  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. css: {
  259. preprocessorOptions: {
  260. scss: {
  261. api: "modern",
  262. },
  263. },
  264. },
  265. })