DevServer

Rspack CLI comes with a built-in @rspack/dev-server for development and debugging. Its capabilities are similar to webpack-dev-server, including features like Hot Module Replacement (HMR), proxy server and more.

TIP

webpack-dev-server@5 is used in @rspack/dev-server, which has some differences from webpack-dev-server@4.

HMR

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

module.exports = {
  devServer: {
    hot: false,
  },
};
WARNING

HMR is not working for CSS when output.cssFilename contains [hash] or [contenthash]

Proxy

Rspack has a built-in simple proxy server. You can enable the proxy server by configuring the devServer.proxy option in rspack.config.js. The devServer internally uses http-proxy-middleware to implement the proxy function. For example, you can proxy /api to http://localhost:3000 as follows:

module.exports = {
  devServer: {
    proxy: [
      {
        context: ['/api'],
        target: 'http://localhost:3000',
        changeOrigin: true,
      },
    ],
  },
};

For more devServer configuration options, please refer to devServer.

ON THIS PAGE