vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /// <reference types="vitest" />
  2. import path from 'node:path'
  3. import { defineConfig } from 'vite'
  4. import Vue from '@vitejs/plugin-vue'
  5. import Pages from 'vite-plugin-pages'
  6. import Components from 'unplugin-vue-components/vite'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. // import WindiCSS from 'vite-plugin-windicss'
  9. import UnoCSS from 'unocss/vite'
  10. import VueMacros from 'unplugin-vue-macros/vite'
  11. import { VantResolver } from 'unplugin-vue-components/resolvers'
  12. import legacyPlugin from '@vitejs/plugin-legacy'
  13. export default defineConfig({
  14. base: '',
  15. resolve: {
  16. alias: {
  17. '~/': `${path.resolve(__dirname, 'src')}/`,
  18. },
  19. },
  20. server: {
  21. hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
  22. },
  23. plugins: [
  24. legacyPlugin({
  25. targets: ['chrome 52'], // 需要兼容的目标列表,可以设置多个
  26. additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
  27. }),
  28. VueMacros({
  29. defineOptions: false,
  30. defineModels: false,
  31. plugins: {
  32. vue: Vue({
  33. script: {
  34. propsDestructure: true,
  35. defineModel: true,
  36. },
  37. }),
  38. },
  39. }),
  40. // https://github.com/hannoeru/vite-plugin-pages
  41. Pages(
  42. {
  43. dirs: 'src/pages',
  44. exclude: ['**/components/*.vue'],
  45. },
  46. ),
  47. // https://github.com/antfu/unplugin-auto-import
  48. AutoImport({
  49. imports: [
  50. 'vue',
  51. 'vue/macros',
  52. 'vue-router',
  53. '@vueuse/core',
  54. ],
  55. dts: true,
  56. dirs: [
  57. './src/composables',
  58. './src/request',
  59. './src/utils',
  60. ],
  61. vueTemplate: true,
  62. resolvers: [
  63. ],
  64. }),
  65. // https://github.com/antfu/vite-plugin-components
  66. Components({
  67. dirs: ['src/components/'],
  68. // allow auto load markdown components under `./src/components/`
  69. extensions: ['vue', 'md'],
  70. // allow auto import and register components used in markdown
  71. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  72. resolvers: [VantResolver()],
  73. }),
  74. // https://github.com/antfu/unocss
  75. // see uno.config.ts for config
  76. // WindiCSS(),
  77. UnoCSS(),
  78. ],
  79. // https://github.com/vitest-dev/vitest
  80. // test: {
  81. // environment: 'jsdom',
  82. // },
  83. })