vite-plugin-proxy
raw JSON → 0.5.0 verified Mon Apr 27 auth: no javascript
A Vite plugin that provides webpack-dev-server-style proxy functionality for Vite's dev server, wrapping http-proxy-middleware. Current stable version is 0.5.0. Release cadence is low. Key differentiator: offers a familiar API for webpack users migrating to Vite, with full http-proxy-middleware options support. Note: Vite 2+ includes built-in proxy support via server.proxy, which is the recommended approach; this plugin is primarily for those wanting an explicit plugin or custom HTTP proxy middleware behavior.
Common errors
error Error: Cannot find module 'vite-plugin-proxy' ↓
cause Package not installed or incorrect import path.
fix
Install the package: npm install vite-plugin-proxy --save-dev
error TypeError: proxyPlugin is not a function ↓
cause Using default import incorrectly (e.g., import { proxyPlugin } ... instead of import proxyPlugin ...)
fix
Use default import: import proxyPlugin from 'vite-plugin-proxy'
Warnings
deprecated Vite 2+ has built-in proxy support via server.proxy. Using this plugin is now redundant for most use cases. ↓
fix Use Vite's built-in proxy: export default defineConfig({ server: { proxy: { '/api': { target: 'http://example.com' } } } });
gotcha Plugin options are passed directly to http-proxy-middleware. Some options may behave differently in Vite's context (e.g., pathRewrite). ↓
fix Refer to http-proxy-middleware documentation; test thoroughly with your Vite version.
gotcha The plugin only works during dev server. Not applicable for production builds. ↓
fix Use environment checks or conditionally apply the plugin only in dev mode: plugins: [process.env.NODE_ENV === 'development' && proxyPlugin(...)].filter(Boolean)
Install
npm install vite-plugin-proxy yarn add vite-plugin-proxy pnpm add vite-plugin-proxy Imports
- vite-plugin-proxy (default) wrong
const proxyPlugin = require('vite-plugin-proxy')correctimport proxyPlugin from 'vite-plugin-proxy' - proxy (named, if re-exported) wrong
import { proxy } from 'vite-plugin-proxy'correctimport proxyPlugin from 'vite-plugin-proxy' - ProxyOptions (type) wrong
import type { ProxyOptions } from 'vite-plugin-proxy'correctimport type { ProxyOptions } from 'vite'
Quickstart
import { defineConfig } from 'vite';
import proxyPlugin from 'vite-plugin-proxy';
export default defineConfig({
plugins: [
proxyPlugin({
'/api': {
target: 'https://reqres.in',
changeOrigin: true,
onProxyRes: (proxyRes) => {
proxyRes.headers['Cache-Control'] = `public, max-age=${365 * 24 * 60 * 60}`;
delete proxyRes.headers['expires'];
},
},
}),
],
});