vite.config.ts 1.9 KB

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