vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 topLevelAwait from 'vite-plugin-top-level-await'
  14. import ConditionalCompile from './plugins/vite-plugin-conditional-compile'
  15. export default defineConfig(({ command }) => {
  16. const cfg = {
  17. base: '',
  18. server: {
  19. open: true,
  20. port: 8081,
  21. host: '0.0.0.0',
  22. },
  23. resolve: {
  24. alias: {
  25. '~/': `${path.resolve(__dirname, 'src')}/`,
  26. '@': `${path.resolve(__dirname, 'src')}`,
  27. },
  28. },
  29. plugins: [
  30. ConditionalCompile(),
  31. topLevelAwait({
  32. // The export name of top-level await promise for each chunk module
  33. promiseExportName: '__tla',
  34. // The function to generate import names of top-level await promise in each chunk module
  35. promiseImportName: i => `__tla_${i}`,
  36. }),
  37. VueMacros({
  38. plugins: {
  39. vue: Vue({
  40. reactivityTransform: true,
  41. }),
  42. },
  43. }),
  44. WindiCss(),
  45. // https://github.com/hannoeru/vite-plugin-pages
  46. Pages({ extensions: ['vue'] }),
  47. // https://github.com/antfu/unplugin-auto-import
  48. AutoImport({
  49. imports: [
  50. 'vue',
  51. 'vue/macros',
  52. 'vue-router',
  53. '@vueuse/core',
  54. ],
  55. dts: true,
  56. dirs: [
  57. './src/composables',
  58. ],
  59. vueTemplate: true,
  60. resolvers: [ElementPlusResolver()],
  61. }),
  62. // https://github.com/antfu/vite-plugin-components
  63. Components({
  64. dts: true,
  65. resolvers: [ElementPlusResolver(), IconsResolver()],
  66. }),
  67. Icons({
  68. compiler: 'vue3',
  69. autoInstall: true,
  70. }),
  71. // https://github.com/antfu/unocss
  72. // see unocss.config.ts for config
  73. ],
  74. // https://github.com/vitest-dev/vitest
  75. test: {
  76. environment: 'jsdom',
  77. },
  78. }
  79. if (command === 'build') {
  80. cfg.base = '/webapps/page/liankao/'
  81. return cfg
  82. }
  83. else {
  84. return cfg
  85. }
  86. })