vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. import basicSsl from '@vitejs/plugin-basic-ssl'
  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. port: 9901,
  23. https: true,
  24. },
  25. plugins: [
  26. basicSsl(),
  27. legacyPlugin({
  28. targets: ['chrome 52'], // 需要兼容的目标列表,可以设置多个
  29. additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
  30. }),
  31. VueMacros({
  32. defineOptions: false,
  33. defineModels: false,
  34. plugins: {
  35. vue: Vue({
  36. script: {
  37. propsDestructure: true,
  38. defineModel: true,
  39. },
  40. }),
  41. },
  42. }),
  43. // https://github.com/hannoeru/vite-plugin-pages
  44. Pages(
  45. {
  46. dirs: 'src/pages',
  47. exclude: ['**/components/*.vue'],
  48. },
  49. ),
  50. // https://github.com/antfu/unplugin-auto-import
  51. AutoImport({
  52. imports: [
  53. 'vue',
  54. 'vue/macros',
  55. 'vue-router',
  56. '@vueuse/core',
  57. ],
  58. dts: true,
  59. dirs: [
  60. // './src/composables',
  61. './src/request',
  62. './src/utils',
  63. ],
  64. vueTemplate: true,
  65. resolvers: [
  66. ],
  67. }),
  68. // https://github.com/antfu/vite-plugin-components
  69. Components({
  70. dirs: ['src/components/'],
  71. // allow auto load markdown components under `./src/components/`
  72. extensions: ['vue', 'md'],
  73. // allow auto import and register components used in markdown
  74. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  75. resolvers: [VantResolver()],
  76. }),
  77. // https://github.com/antfu/unocss
  78. // see uno.config.ts for config
  79. // WindiCSS(),
  80. UnoCSS(),
  81. ],
  82. // https://github.com/vitest-dev/vitest
  83. // test: {
  84. // environment: 'jsdom',
  85. // },
  86. })