vite.config.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { defineConfig, loadEnv } from 'vite'
  2. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  3. import vue from '@vitejs/plugin-vue'
  4. import ViteComponents from 'unplugin-vue-components/vite'
  5. import DefineOptions from 'unplugin-vue-define-options/vite'
  6. import { resolve } from 'path'
  7. // https://vitejs.dev/config/
  8. export default ({ mode }) => {
  9. const env = loadEnv(mode, process.cwd())
  10. const proxy = {
  11. '/api': {
  12. target: 'https://test.4dkankan.com',
  13. changeOrigin: true,
  14. rewrite: path => path.replace(/^\/api/, '')
  15. },
  16. '/local': {
  17. target: 'http://192.168.0.152:8111',
  18. changeOrigin: true,
  19. rewrite: path => path.replace(/^\/local/, '')
  20. }
  21. }
  22. return defineConfig({
  23. base: './',
  24. plugins: [
  25. vue(),
  26. DefineOptions(),
  27. ViteComponents({
  28. resolvers: [
  29. AntDesignVueResolver({ resolveIcons: true, importStyle: 'less' })
  30. ],
  31. dts: 'src/components.d.ts'
  32. })
  33. ],
  34. css: {
  35. preprocessorOptions: {
  36. less: {
  37. javascriptEnabled: true,
  38. modifyVars: {
  39. 'primary-color': '#0076F6',
  40. 'link-color': '#0076F6',
  41. 'border-radius-base': '2px'
  42. }
  43. }
  44. }
  45. },
  46. resolve: {
  47. alias: [
  48. {
  49. find: '@',
  50. replacement: resolve(__dirname, './src')
  51. }
  52. ]
  53. },
  54. server: {
  55. host: '0.0.0.0',
  56. port: 5173,
  57. open: true,
  58. proxy: proxy
  59. }
  60. })
  61. }