vite.config.ts 2.7 KB

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