vite.config.ts 2.2 KB

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