You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

vite.config.ts 4.0 kB

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