vite.config.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueDevTools from 'vite-plugin-vue-devtools'
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import { TDesignResolver } from 'unplugin-vue-components/resolvers'
  8. // https://vitejs.dev/config/
  9. export default defineConfig(({ command, mode }) => {
  10. const env = loadEnv(mode, process.cwd(), '')
  11. return {
  12. plugins: [
  13. vue(),
  14. AutoImport({
  15. imports:['vue'],
  16. dts:"src/auto-import.d.ts" // 会自动生成此文件
  17. }),
  18. vueDevTools(),
  19. AutoImport({
  20. resolvers: [
  21. TDesignResolver({
  22. library: 'vue-next'
  23. })
  24. ]
  25. }),
  26. Components({
  27. resolvers: [
  28. TDesignResolver({
  29. library: 'vue-next'
  30. })
  31. ]
  32. }),
  33. ],
  34. resolve: {
  35. alias: {
  36. '@': fileURLToPath(new URL('./src', import.meta.url))
  37. }
  38. },
  39. server: {
  40. proxy: {
  41. '/api': {
  42. target: env.VITE_PROXY_ENDPOINT,
  43. changeOrigin: true,
  44. // rewrite: (path) => path.replace(/^\/api/, '')
  45. }
  46. }
  47. }
  48. }
  49. })