dev.setupMiddlewares
- Type:
- Default:
undefined - Version:
>= 1.4.0
Used to add custom middleware to the dev server.
See Dev server - Middleware for more information.
Basic usage
setupMiddlewares function receives a middlewares array, you can add custom middleware by unshift and push methods:
- Use
unshiftto prepend middleware to the array, executed earlier than the built-in middleware. - Use
pushto append middleware to the array, executed later than the built-in middleware.
The middleware can be an async function:
setupMiddlewares also supports passing an array, each item of which is a function to set up middlewares:
In versions before Rsbuild 1.4.0, setupMiddlewares must pass an array.
Context object
The second parameter of the setupMiddlewares function is the context object, which provides some server context and APIs.
environments
Provides Rsbuild's environment API, see Dev server API - environments for more details.
sockWrite
Sends some message to HMR client, see Dev server API - sockWrite for more details.
For example, if you send a 'static-changed' message, the page will reload.

