index.ts 3.6 KB

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