vite.config.ts 4.8 KB

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