vite.config.ts 6.7 KB

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