vite.config.ts 6.9 KB

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