vite.config.ts 4.5 KB

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