undefined
>= 1.4.0
Used to add custom middleware to the dev server.
See Dev server - Middleware for more information.
setupMiddlewares
function receives a middlewares
array, you can add custom middleware by unshift
and push
methods:
unshift
to prepend middleware to the array, executed earlier than the built-in middleware.push
to append middleware to the array, executed later than the built-in middleware.setupMiddlewares
also supports passing an array, each item of which is a function to setup middlewares:
In versions before Rsbuild 1.4.0, setupMiddlewares
must pass an array.
The second parameter of the setupMiddlewares
function is the context
object, which provides some server context and APIs.
Provides Rsbuild's environment API, see Dev server API - environments for more details.
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.