index.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { dirname, resolve } from 'node:path'
  2. import { fileURLToPath } from 'node:url'
  3. import { unheadVueComposablesImports } from '@unhead/vue'
  4. import legacy from '@vitejs/plugin-legacy'
  5. import vue from '@vitejs/plugin-vue'
  6. import UnoCSS from 'unocss/vite'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import { VantResolver } from 'unplugin-vue-components/resolvers'
  9. import Components from 'unplugin-vue-components/vite'
  10. import { VueRouterAutoImports } from 'unplugin-vue-router'
  11. import VueRouter from 'unplugin-vue-router/vite'
  12. import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
  13. import { VitePWA } from 'vite-plugin-pwa'
  14. import Sitemap from 'vite-plugin-sitemap'
  15. import VueDevTools from 'vite-plugin-vue-devtools'
  16. import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
  17. import { createViteVConsole } from './vconsole'
  18. export function createVitePlugins() {
  19. return [
  20. // https://github.com/posva/unplugin-vue-router
  21. VueRouter({
  22. extensions: ['.vue'],
  23. routesFolder: 'src/pages',
  24. dts: 'src/typed-router.d.ts',
  25. }),
  26. vue(),
  27. // https://github.com/jbaubree/vite-plugin-sitemap
  28. Sitemap(),
  29. // https://github.com/pengzhanbo/vite-plugin-mock-dev-server
  30. mockDevServerPlugin(),
  31. // https://github.com/antfu/unplugin-vue-components
  32. Components({
  33. extensions: ['vue'],
  34. resolvers: [VantResolver()],
  35. include: [/\.vue$/, /\.vue\?vue/],
  36. dts: 'src/components.d.ts',
  37. }),
  38. // https://github.com/antfu/unplugin-auto-import
  39. AutoImport({
  40. include: [
  41. /\.[tj]sx?$/,
  42. /\.vue$/,
  43. /\.vue\?vue/,
  44. ],
  45. imports: [
  46. 'vue',
  47. 'vitest',
  48. '@vueuse/core',
  49. VueRouterAutoImports,
  50. {
  51. 'vue-router/auto': ['useLink'],
  52. '@/utils/i18n': ['i18n', 'locale'],
  53. 'vue-i18n': ['useI18n'],
  54. },
  55. unheadVueComposablesImports,
  56. ],
  57. dts: 'src/auto-imports.d.ts',
  58. dirs: [
  59. 'src/composables',
  60. ],
  61. viteOptimizeDeps: false,
  62. }),
  63. // https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
  64. VueI18nPlugin({
  65. // locale messages resource pre-compile option
  66. include: resolve(dirname(fileURLToPath(import.meta.url)), '../../src/locales/**'),
  67. }),
  68. legacy({
  69. targets: ['defaults', 'not IE 11'],
  70. }),
  71. // https://github.com/antfu/unocss
  72. // see uno.config.ts for config
  73. UnoCSS(),
  74. // https://github.com/vadxq/vite-plugin-vconsole
  75. createViteVConsole(),
  76. // https://github.com/vuejs/devtools-next
  77. VueDevTools(),
  78. // https://github.com/antfu/vite-plugin-pwa
  79. VitePWA({
  80. registerType: 'autoUpdate',
  81. includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
  82. manifest: {
  83. name: 'vue3-vant-mobile',
  84. short_name: 'vue3-vant-mobile',
  85. theme_color: '#ffffff',
  86. icons: [
  87. {
  88. src: '/pwa-192x192.png',
  89. sizes: '192x192',
  90. type: 'image/png',
  91. },
  92. {
  93. src: '/pwa-512x512.png',
  94. sizes: '512x512',
  95. type: 'image/png',
  96. },
  97. {
  98. src: '/pwa-512x512.png',
  99. sizes: '512x512',
  100. type: 'image/png',
  101. purpose: 'any maskable',
  102. },
  103. ],
  104. },
  105. }),
  106. ]
  107. }