vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. 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. https: true,
  22. hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
  23. },
  24. plugins: [
  25. basicSsl(),
  26. legacyPlugin({
  27. targets: ['chrome 52'], // 需要兼容的目标列表,可以设置多个
  28. additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // 面向IE11时需要此插件
  29. }),
  30. VueMacros({
  31. defineOptions: false,
  32. defineModels: false,
  33. plugins: {
  34. vue: Vue({
  35. script: {
  36. propsDestructure: true,
  37. defineModel: true,
  38. },
  39. }),
  40. },
  41. }),
  42. // https://github.com/hannoeru/vite-plugin-pages
  43. Pages(
  44. {
  45. dirs: 'src/pages',
  46. exclude: ['**/components/*.vue'],
  47. extensions: ['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/request',
  61. // './src/utils',
  62. ],
  63. vueTemplate: true,
  64. resolvers: [
  65. ],
  66. }),
  67. // https://github.com/antfu/vite-plugin-components
  68. Components({
  69. dirs: ['src/components/'],
  70. // allow auto load markdown components under `./src/components/`
  71. extensions: ['vue', 'md'],
  72. // allow auto import and register components used in markdown
  73. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  74. resolvers: [VantResolver()],
  75. }),
  76. // https://github.com/antfu/unocss
  77. // see uno.config.ts for config
  78. WindiCSS(),
  79. ],
  80. // https://github.com/vitest-dev/vitest
  81. test: {
  82. environment: 'jsdom',
  83. },
  84. build: {
  85. minify: 'terser',
  86. terserOptions: {
  87. compress: {
  88. drop_console: true,
  89. },
  90. },
  91. },
  92. })