vite.config.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 VueMacros from 'unplugin-vue-macros/vite'
  10. import { VantResolver } from 'unplugin-vue-components/resolvers'
  11. export default defineConfig({
  12. base: '/',
  13. resolve: {
  14. alias: {
  15. '~/': `${path.resolve(__dirname, 'src')}/`,
  16. },
  17. },
  18. server: {
  19. hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
  20. },
  21. plugins: [
  22. VueMacros({
  23. defineOptions: false,
  24. defineModels: false,
  25. plugins: {
  26. vue: Vue({
  27. script: {
  28. propsDestructure: true,
  29. defineModel: true,
  30. },
  31. }),
  32. },
  33. }),
  34. // https://github.com/hannoeru/vite-plugin-pages
  35. Pages(
  36. {
  37. dirs: 'src/pages',
  38. exclude: ['**/components/*.vue'],
  39. },
  40. ),
  41. // https://github.com/antfu/unplugin-auto-import
  42. AutoImport({
  43. imports: [
  44. 'vue',
  45. 'vue/macros',
  46. 'vue-router',
  47. '@vueuse/core',
  48. ],
  49. dts: true,
  50. dirs: [
  51. './src/composables',
  52. './src/request',
  53. './src/utils',
  54. ],
  55. vueTemplate: true,
  56. resolvers: [
  57. ],
  58. }),
  59. // https://github.com/antfu/vite-plugin-components
  60. Components({
  61. dirs: ['src/components/'],
  62. // allow auto load markdown components under `./src/components/`
  63. extensions: ['vue', 'md'],
  64. // allow auto import and register components used in markdown
  65. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  66. resolvers: [VantResolver()],
  67. }),
  68. // https://github.com/antfu/unocss
  69. // see uno.config.ts for config
  70. WindiCSS(),
  71. ],
  72. // https://github.com/vitest-dev/vitest
  73. test: {
  74. environment: 'jsdom',
  75. },
  76. })