vite.config.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import path from 'node:path'
  2. import { defineConfig } from 'vite'
  3. import Vue from '@vitejs/plugin-vue'
  4. import Pages from 'vite-plugin-pages'
  5. import Components from 'unplugin-vue-components/vite'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. // import WindiCSS from 'vite-plugin-windicss'
  8. import UnoCSS from 'unocss/vite'
  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. port: 9901
  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. })