Vite 2.x 中使用 export default defineConfig 配置代理
要将 Vite 中的 module.exports 配置转换为使用 export default defineConfig,可以按照以下步骤进行修改:
import { defineConfig } from 'vite'
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://目标服务器地址',
changeOrigin: true,
rewrite: (path) => path.replace(/^/api/, '')
}
}
}
})
在这里,我们使用了 import 语句引入了 defineConfig 函数,并且使用 export default 导出了配置对象。还要注意,pathRewrite 属性在 Vite 2.x 中被替换为了 rewrite 属性。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qbk4 著作权归作者所有。请勿转载和采集!