vite.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /// <reference types="vitest" />
  2. import path from 'node:path'
  3. import { defineConfig } from 'vite'
  4. import Vue from '@vitejs/plugin-vue'
  5. import WindiCss from 'vite-plugin-windicss'
  6. import Pages from 'vite-plugin-pages'
  7. import Components from 'unplugin-vue-components/vite'
  8. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  9. import AutoImport from 'unplugin-auto-import/vite'
  10. import VueMacros from 'unplugin-vue-macros/vite'
  11. import Icons from 'unplugin-icons/vite'
  12. import IconsResolver from 'unplugin-icons/resolver'
  13. import ConditionalCompile from './plugins/vite-plugin-conditional-compile'
  14. export default defineConfig(({ command }) => {
  15. const cfg = {
  16. base: '',
  17. resolve: {
  18. alias: {
  19. '~/': `${path.resolve(__dirname, 'src')}/`,
  20. '@': `${path.resolve(__dirname, 'src')}`,
  21. },
  22. },
  23. plugins: [
  24. ConditionalCompile(),
  25. VueMacros({
  26. plugins: {
  27. vue: Vue({
  28. reactivityTransform: true,
  29. }),
  30. },
  31. }),
  32. WindiCss(),
  33. // https://github.com/hannoeru/vite-plugin-pages
  34. Pages({ extensions: ['vue'] }),
  35. // https://github.com/antfu/unplugin-auto-import
  36. AutoImport({
  37. imports: [
  38. 'vue',
  39. 'vue/macros',
  40. 'vue-router',
  41. '@vueuse/core',
  42. ],
  43. dts: true,
  44. dirs: [
  45. './src/composables',
  46. ],
  47. vueTemplate: true,
  48. resolvers: [ElementPlusResolver()],
  49. }),
  50. // https://github.com/antfu/vite-plugin-components
  51. Components({
  52. dts: true,
  53. resolvers: [ElementPlusResolver(), IconsResolver()],
  54. }),
  55. Icons({
  56. compiler: 'vue3',
  57. autoInstall: true,
  58. }),
  59. // https://github.com/antfu/unocss
  60. // see unocss.config.ts for config
  61. ],
  62. // https://github.com/vitest-dev/vitest
  63. test: {
  64. environment: 'jsdom',
  65. },
  66. }
  67. if (command === 'build') {
  68. cfg.base = '/webapps/page/liankao/'
  69. return cfg
  70. }
  71. else {
  72. return cfg
  73. }
  74. })