close

Dev server

The rspack dev and rspack serve commands run a local development server through @rspack/dev-server. It provides hot module replacement (HMR), static file serving, proxying, and related development features.

Install dev server

@rspack/dev-server is an optional peer dependency of @rspack/cli.

Install it before using rspack dev, rspack serve, or rspack preview:

npm
yarn
pnpm
bun
deno
npm add @rspack/dev-server -D

HMR

By default, Rspack enables HMR in dev mode. You can disable HMR by configuring the devServer.hot option in Rspack configuration.

rspack.config.mjs
export default {
  devServer: {
    hot: false,
  },
};
Warning

Do not include [hash] or [contenthash] in output.cssFilename, otherwise CSS HMR may not work.

Proxy

The dev server includes proxy support. Configure the devServer.proxy option to proxy matching requests. This feature is powered by http-proxy-middleware. For example, you can proxy /api to http://localhost:3000 as follows:

rspack.config.mjs
export default {
  devServer: {
    proxy: [
      {
        context: ['/api'],
        target: 'http://localhost:3000',
        changeOrigin: true,
      },
    ],
  },
};

For more devServer configuration options, please refer to devServer.