vite 代理配置

6,926 阅读1分钟
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      "comps": path.resolve(__dirname, "src/components"),
    },
  },
  css:{
    preprocessorOptions:{
      // scss:{
      //   additionalData:'@import "/src/assets/style/theme.scss";'
      // }
      less:{
        additionalData:'@import "/src/assets/style/common.less";'
      }
    }
  },
  server: {
    // host: '192.168.0.45',
    // port: 8080,
    proxy: {
      // 接口地址代理
      '/demo': {
        target: 'http://192.168.0.238:8088', // 接口的域名
        secure: false, // 如果是https接口,需要配置这个参数
        changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
        rewrite: path => path.replace(/^\/demo/, '/demo')
      },
    }
  },
})