A monorepo project that provides CRA-style proxy support for Rsbuild and Vite.
Use API proxy in Rsbuild and Vite development environments just like in Create React App.
- ✅ CRA-style Configuration: Set the
proxyfield directly inpackage.json - ✅ HTTP & WebSocket Proxy: Support proxying HTTP requests and custom WebSocket connections
- ✅ Smart HMR Filtering: Automatically exclude dev server HMR connections to avoid conflicts
- ✅ Windows Compatibility: Automatically fix
localhostloopback issues on Windows - ✅ Chrome DevTools Filtering: Exclude auto-folder feature requests
- ✅ Multi-framework Support: Rsbuild v1/v2 and Vite implementations
- ✅ Middleware Plugin: Reuse the same proxy logic with independent framework adapters
This is a pnpm workspaces monorepo with 3 core packages:
- npm package:
@plugin-cra-proxy/core - Purpose: Core middleware implementation for proxy
- Main Features:
- Read
proxyfield frompackage.json - Implement HTTP/WebSocket proxy based on
http-proxy-middleware - Fix Windows localhost issues
- Provide intelligent request filtering (HMR, DevTools, etc.)
- Read
- npm package:
@plugin-cra-proxy/rsbuild - Purpose: Rsbuild plugin adapter
- Features:
- Compatible with Rsbuild v1 and v2
- v1 uses
dev.setupMiddlewares - v2 uses
server.setup - Ensure proxy executes after all default middlewares
- npm package:
@plugin-cra-proxy/vite - Purpose: Vite plugin adapter
- Features:
- Reuse middleware from
@plugin-cra-proxy/core - Compatible with Vite official plugin system
- Reuse middleware from
npm add @plugin-cra-proxy/rsbuild -Drsbuild.config.ts:
import { pluginCraProxy } from "@plugin-cra-proxy/rsbuild";
export default {
plugins: [pluginCraProxy()],
};package.json:
{
"proxy": "http://localhost:4000"
}npm add @plugin-cra-proxy/vite -Dvite.config.ts:
import { pluginCraProxy } from "@plugin-cra-proxy/vite";
export default {
plugins: [pluginCraProxy()],
};package.json:
{
"proxy": "http://localhost:4000"
}- Configuration Reading: The plugin reads the
proxyfield frompackage.jsonon startup - Middleware Injection: Inject proxy middleware into the dev server backend
- Request Filtering:
- ✅ Requests handled by Rsbuild/Vite (static assets, HMR, HTML) pass through normally
- ✅ DevTools auto-folder requests are filtered
- ❌ HMR WebSocket connections are not proxied
- ➜ All other requests are forwarded to the proxy target server
- Header Fixing: Automatically modify the
Originheader to prevent CORS issues
The project provides 4000.js as a test backend:
npm run server-4000Available routes:
GET /api/user: Returns JSON dataGET /admin: Returns HTML page- Other paths: Returns 404
- Rsbuild v1.x: Uses
config.dev.setupMiddlewaresAPI - Rsbuild v2.x: Uses
config.server.setupAPI
The plugin automatically adapts based on the @rsbuild/core version.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Development mode (watch file changes)
pnpm dev
# Lint code
pnpm lint
# Fix code format
pnpm lint:write
# Run tests
pnpm testMIT