You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vite:如何将vue.config.ts中的devServer配置迁移至vite.config.ts

Vue CLI devServer 代理配置迁移到 Vite 的方法

Vite 中对应的代理配置项是 server.proxy,和你原来 Vue CLI 的配置逻辑基本一致,只需要调整配置结构即可,迁移后的 vite.config.ts 代码如下:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      '^/example/': {
        target: 'http://php:80',
        changeOrigin: true
      }
    }
  }
})

关键说明:

  • 原 Vue CLI 的 devServer.proxy 直接迁移到 Vite 的 server.proxy 节点下
  • 代理的匹配规则、target 和 changeOrigin 参数无需修改,保持原有配置即可
  • Vite 配置文件使用 ES Module 语法(导出 defineConfig 配置对象),这是和 Vue CLI 配置文件的主要语法差异

内容的提问来源于stack exchange,提问作者robtot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 23:45:47