vite.config.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import path from 'node:path'
  2. import VueI18n from '@intlify/unplugin-vue-i18n/vite'
  3. import Shiki from '@shikijs/markdown-it'
  4. import { unheadVueComposablesImports } from '@unhead/vue'
  5. import Vue from '@vitejs/plugin-vue'
  6. import LinkAttributes from 'markdown-it-link-attributes'
  7. import Unocss from 'unocss/vite'
  8. import AutoImport from 'unplugin-auto-import/vite'
  9. import Components from 'unplugin-vue-components/vite'
  10. import VueMacros from 'unplugin-vue-macros/vite'
  11. import Markdown from 'unplugin-vue-markdown/vite'
  12. import { VueRouterAutoImports } from 'unplugin-vue-router'
  13. import VueRouter from 'unplugin-vue-router/vite'
  14. import { defineConfig } from 'vite'
  15. import { VitePWA } from 'vite-plugin-pwa'
  16. // import VueDevTools from 'vite-plugin-vue-devtools'
  17. import Layouts from 'vite-plugin-vue-layouts'
  18. import generateSitemap from 'vite-ssg-sitemap'
  19. import 'vitest/config'
  20. export default defineConfig({
  21. resolve: {
  22. alias: {
  23. '~/': `${path.resolve(__dirname, 'src')}/`,
  24. },
  25. },
  26. plugins: [
  27. VueMacros({
  28. plugins: {
  29. vue: Vue({
  30. include: [/\.vue$/, /\.md$/],
  31. }),
  32. },
  33. }),
  34. // https://github.com/posva/unplugin-vue-router
  35. VueRouter({
  36. extensions: ['.vue', '.md'],
  37. dts: 'src/typed-router.d.ts',
  38. }),
  39. // https://github.com/JohnCampionJr/vite-plugin-vue-layouts
  40. Layouts(),
  41. // https://github.com/antfu/unplugin-auto-import
  42. AutoImport({
  43. include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/],
  44. imports: [
  45. 'vue',
  46. 'vue-i18n',
  47. '@vueuse/core',
  48. unheadVueComposablesImports,
  49. VueRouterAutoImports,
  50. {
  51. // add any other imports you were relying on
  52. 'vue-router/auto': ['useLink'],
  53. },
  54. ],
  55. dts: 'src/auto-imports.d.ts',
  56. dirs: [
  57. 'src/composables',
  58. 'src/stores',
  59. ],
  60. vueTemplate: true,
  61. }),
  62. // https://github.com/antfu/unplugin-vue-components
  63. Components({
  64. // allow auto load markdown components under `./src/components/`
  65. extensions: ['vue', 'md'],
  66. // allow auto import and register components used in markdown
  67. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  68. dts: 'src/components.d.ts',
  69. }),
  70. // https://github.com/antfu/unocss
  71. // see uno.config.ts for config
  72. Unocss(),
  73. // https://github.com/unplugin/unplugin-vue-markdown
  74. // Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
  75. Markdown({
  76. wrapperClasses: 'prose prose-sm m-auto text-left',
  77. headEnabled: true,
  78. async markdownItSetup(md) {
  79. md.use(LinkAttributes, {
  80. matcher: (link: string) => /^https?:\/\//.test(link),
  81. attrs: {
  82. target: '_blank',
  83. rel: 'noopener',
  84. },
  85. })
  86. md.use(await Shiki({
  87. defaultColor: false,
  88. themes: {
  89. light: 'vitesse-light',
  90. dark: 'vitesse-dark',
  91. },
  92. }))
  93. },
  94. }),
  95. // https://github.com/antfu/vite-plugin-pwa
  96. VitePWA({
  97. registerType: 'autoUpdate',
  98. includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
  99. manifest: {
  100. name: 'Vitesse',
  101. short_name: 'Vitesse',
  102. theme_color: '#ffffff',
  103. icons: [
  104. {
  105. src: '/pwa-192x192.png',
  106. sizes: '192x192',
  107. type: 'image/png',
  108. },
  109. {
  110. src: '/pwa-512x512.png',
  111. sizes: '512x512',
  112. type: 'image/png',
  113. },
  114. {
  115. src: '/pwa-512x512.png',
  116. sizes: '512x512',
  117. type: 'image/png',
  118. purpose: 'any maskable',
  119. },
  120. ],
  121. },
  122. }),
  123. // https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
  124. VueI18n({
  125. runtimeOnly: true,
  126. compositionOnly: true,
  127. fullInstall: true,
  128. include: [path.resolve(__dirname, 'locales/**')],
  129. }),
  130. // https://github.com/webfansplz/vite-plugin-vue-devtools
  131. // VueDevTools(),
  132. ],
  133. // https://github.com/vitest-dev/vitest
  134. test: {
  135. include: ['test/**/*.test.ts'],
  136. environment: 'jsdom',
  137. },
  138. // https://github.com/antfu/vite-ssg
  139. ssgOptions: {
  140. script: 'async',
  141. formatting: 'minify',
  142. beastiesOptions: {
  143. reduceInlineStyles: false,
  144. },
  145. onFinished() {
  146. generateSitemap()
  147. },
  148. },
  149. ssr: {
  150. // TODO: workaround until they support native ESM
  151. noExternal: ['workbox-window', /vue-i18n/],
  152. },
  153. })