vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(({ mode }) => {
  13. const config = loadEnv(mode, './');
  14. console.log(config);
  15. return {
  16. base: "./",
  17. plugins: [
  18. vue(),
  19. AutoImport({
  20. //安装两行后你会发现在组件中不用再导入ref,reactive等
  21. imports: ['vue', 'vue-router'],
  22. //存放的位置
  23. dts: "src/auto-import.d.ts",
  24. }),
  25. Components({
  26. // 引入组件的,包括自定义组件,存放的位置
  27. dts: "src/components.d.ts",
  28. }),
  29. VueSetupExtend(),
  30. ],
  31. //1、 ↓解析配置
  32. resolve: {
  33. // ↓路径别名
  34. alias: {
  35. '@': resolve('src')
  36. }
  37. },
  38. //代理
  39. server: {
  40. proxy: {
  41. '/api': {
  42. target: 'http://192.168.0.131:8187/TransServlet',//配置文件获取地址
  43. secure: false, //接受使用https
  44. changeOrigin: true, //允许跨域
  45. ws: false, //使用websocket
  46. rewrite: (path) => path.replace(/^\/api/, '')
  47. },
  48. '/file': {
  49. // target: 'http://192.168.0.15:8081/', // 后端接口地址
  50. target: 'http://192.168.0.43:2201/',
  51. secure: false, //接受使用https
  52. changeOrigin: true, //允许跨域
  53. ws: false, //使用websocket
  54. pathRewrite: { // 路径重写
  55. '^/file': ''
  56. }
  57. }, '/websokct': {
  58. target: 'http://192.168.0.131:8081/',
  59. // target: 'http://192.168.0.43:8081/',
  60. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  61. secure: false, //接受使用https
  62. },
  63. }
  64. }
  65. }
  66. })