
开发环境使用接口代理服务
主题使用的接口,没有使用配置,都是用的相对路径地址。
所以要求在使用时,要特殊处理。
本地开发时,可通过配置Vite代理方式使用。
VitePress的底层就是Vite,所以配置方式与支持的配置项也是与Vite一样的。
配置文件
配置文件: docs/.vitepress/config.js
import {defineConfig} from 'vitepress'
//更多配置请查看文档 https://vitepress.dev/zh/reference/site-config
export default defineConfig({
title: "VitePress 会员主题",
vite: {
assetsInclude: ['**/*.awebp', '**/*.webp'],
server: {
proxy: {
'/vpapi/': {target: 'http://localhost:80', changeOrigin: true},
}
},
plugins: [ ]
},
})
按需配置vite.server.proxy
,其中/vpapi/
是主题中所有接口的前缀,target
是目标服务地址。