Development server for rspack
npm install @rspack/dev-serverUse Rspack with a development server that provides live reloading. This should be used for development only.
> @rspack/dev-server is based on webpack-dev-server@5
First of all, install @rspack/dev-server and @rspack/core by your favorite package manager:
``bashnpm
$ npm install @rspack/dev-server @rspack/core --save-dev
Usage
There are two recommended ways to use
@rspack/dev-server:$3
@rspack/cli.You can install it in your project by:
`bash
npm
$ npm install @rspack/cli --save-devyarn
$ yarn add @rspack/cli --devpnpm
$ pnpm add @rspack/cli --save-devbun
$ bun add @rspack/cli -D
`And then start the development server by:
`bash
with rspack.config.js
$ rspack servewith custom config file
$ rspack serve -c ./your.config.js
`> See CLI for more details.
While starting the development server, you can specify the configuration by the
devServer field of your Rspack config file:`js
// rspack.config.mjs
export default {
// ...
devServer: {
// the configuration of the development server
port: 8080,
},
};
`> See DevServer for all configuration options.
$3
While it's recommended to run
@rspack/dev-server via the CLI, you may also choose to start a server via the API.`js
import { RspackDevServer } from '@rspack/dev-server';
import rspack from '@rspack/core';
import rspackConfig from './rspack.config.mjs';const compiler = rspack(rspackConfig);
const devServerOptions = {
...rspackConfig.devServer,
// override
port: 8888,
};
const server = new RspackDevServer(devServerOptions, compiler);
server.startCallback(() => {
console.log('Successfully started server on http://localhost:8888');
});
`> Cause
@rspack/dev-server is based on webpack-dev-server@5`, you can see the webpack-dev-server API for more methods of the server instance.This plugin is forked from webpack-dev-server, and is used to smooth out some differences between rspack and webpack, while also providing rspack-specific new features.
> Thanks to the webpack-dev-server project created by @sokra