vite.config.ts 2.1 KB

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