vite.config.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { defineConfig,loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. //1、 导入 path 模块,帮助我们解析路径
  4. import { resolve } from 'path'
  5. //2-1 自动导入vue中hook reactive ref等
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. //2-2 自动导入ui-组件 比如说ant-design-vue element-plus等
  8. import Components from 'unplugin-vue-components/vite'
  9. //3、vue3语法糖
  10. import VueSetupExtend from 'vite-plugin-vue-setup-extend'
  11. // https://vitejs.dev/config/
  12. export default defineConfig(({command,mode})=>{
  13. const config = loadEnv (mode,'./');
  14. return{
  15. base:"./",
  16. plugins: [
  17. vue(),
  18. AutoImport({
  19. //安装两行后你会发现在组件中不用再导入ref,reactive等
  20. imports: ['vue', 'vue-router'],
  21. //存放的位置
  22. dts: "src/auto-import.d.ts",
  23. }),
  24. Components({
  25. // 引入组件的,包括自定义组件,存放的位置
  26. dts: "src/components.d.ts",
  27. }),
  28. VueSetupExtend(),
  29. ],
  30. //1、 ↓解析配置
  31. resolve: {
  32. // ↓路径别名
  33. alias: {
  34. '@': resolve('src')
  35. }
  36. },
  37. //代理
  38. server: {
  39. proxy: {
  40. '/api': {
  41. target: config.VITE_BASE_URL,//配置文件获取地址
  42. secure: false, //接受使用https
  43. changeOrigin: true, //允许跨域
  44. ws: false, //使用websocket
  45. rewrite: (path)=>path.replace(/^\/api/,'')
  46. },
  47. '/file': {
  48. // target: 'http://192.168.0.15:8081/', // 后端接口地址
  49. target: 'http://192.168.0.43:2201/',
  50. secure: false, //接受使用https
  51. changeOrigin: true, //允许跨域
  52. ws: false, //使用websocket
  53. pathRewrite: { // 路径重写
  54. '^/file': ''
  55. }
  56. }, '/websokct':{
  57. target: 'http://192.168.0.131:8081/',
  58. // target: 'http://192.168.0.43:8081/',
  59. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  60. secure: false, //接受使用https
  61. },
  62. }
  63. }
  64. }
  65. })