vite.config.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 { VitePluginFonts } from "vite-plugin-fonts"
  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. return generateSitemap({
  81. routes,
  82. nuxtStyle: true,
  83. allowRobots: true,
  84. dest: ".sitemap-gen",
  85. hostname: ENV.VITE_BASE_URL,
  86. })
  87. },
  88. }),
  89. StaticCopy({
  90. targets: [
  91. {
  92. src: normalizePath(path.resolve(__dirname, "./.sitemap-gen/*")),
  93. dest: normalizePath(path.resolve(__dirname, "./dist")),
  94. },
  95. ],
  96. }),
  97. Layouts({
  98. layoutsDirs: "../hoppscotch-common/src/layouts",
  99. defaultLayout: "default",
  100. }),
  101. VueI18n({
  102. runtimeOnly: false,
  103. compositionOnly: true,
  104. include: [path.resolve(__dirname, "locales")],
  105. }),
  106. WindiCSS({
  107. root: path.resolve(__dirname, "../hoppscotch-common"),
  108. }),
  109. Components({
  110. dts: "../hoppscotch-common/src/components.d.ts",
  111. dirs: [
  112. "../hoppscotch-common/src/components",
  113. "../hoppscotch-ui/src/components",
  114. ],
  115. directoryAsNamespace: true,
  116. resolvers: [
  117. IconResolver({
  118. prefix: "icon",
  119. customCollections: ["hopp", "auth", "brands"],
  120. }),
  121. (compName: string) => {
  122. if (compName.startsWith("Hopp"))
  123. return { name: compName, from: "@hoppscotch/ui" }
  124. else return undefined
  125. },
  126. ],
  127. types: [
  128. {
  129. from: "vue-tippy",
  130. names: ["Tippy"],
  131. },
  132. ],
  133. }),
  134. Icons({
  135. compiler: "vue3",
  136. customCollections: {
  137. hopp: FileSystemIconLoader("../hoppscotch-common/assets/icons"),
  138. auth: FileSystemIconLoader("../hoppscotch-common/assets/icons/auth"),
  139. brands: FileSystemIconLoader(
  140. "../hoppscotch-common/assets/icons/brands"
  141. ),
  142. },
  143. }),
  144. VitePWA({
  145. manifest: {
  146. name: APP_INFO.name,
  147. short_name: APP_INFO.name,
  148. description: APP_INFO.shortDescription,
  149. start_url: "/?source=pwa",
  150. id: "/?source=pwa",
  151. protocol_handlers: [
  152. {
  153. protocol: "web+hoppscotch",
  154. url: "/%s",
  155. },
  156. {
  157. protocol: "web+hopp",
  158. url: "/%s",
  159. },
  160. ],
  161. background_color: APP_INFO.app.background,
  162. theme_color: APP_INFO.app.background,
  163. icons: [
  164. {
  165. src: "/icons/pwa-16x16.png",
  166. sizes: "16x16",
  167. type: "image/png",
  168. },
  169. {
  170. src: "/icons/pwa-32x32.png",
  171. sizes: "32x32",
  172. type: "image/png",
  173. },
  174. {
  175. src: "/icons/pwa-128x128.png",
  176. sizes: "128x128",
  177. type: "image/png",
  178. },
  179. {
  180. src: "/icons/pwa-192x192.png",
  181. sizes: "192x192",
  182. type: "image/png",
  183. },
  184. {
  185. src: "/icons/pwa-256x256.png",
  186. sizes: "256x256",
  187. type: "image/png",
  188. },
  189. {
  190. src: "/icons/pwa-512x512.png",
  191. sizes: "512x512",
  192. type: "image/png",
  193. },
  194. {
  195. src: "/icons/pwa-1024x1024.png",
  196. sizes: "1024x1024",
  197. type: "image/png",
  198. },
  199. ],
  200. },
  201. registerType: "prompt",
  202. workbox: {
  203. cleanupOutdatedCaches: true,
  204. maximumFileSizeToCacheInBytes: 4194304,
  205. navigateFallbackDenylist: [
  206. /robots.txt/,
  207. /sitemap.xml/,
  208. /discord/,
  209. /telegram/,
  210. /beta/,
  211. /careers/,
  212. /newsletter/,
  213. /twitter/,
  214. /github/,
  215. /announcements/,
  216. ],
  217. },
  218. }),
  219. VitePluginFonts({
  220. google: {
  221. families: [
  222. "Inter:wght@400;500;600;700;800",
  223. "Roboto+Mono:wght@400;500",
  224. "Material+Icons",
  225. ],
  226. },
  227. }),
  228. legacy({
  229. modernPolyfills: ["es.string.replace-all"],
  230. renderLegacyChunks: false,
  231. }),
  232. ],
  233. })