Object
{}
The config of DevServer can be modified through tools.devServer
.
Modern.js does not directly use webpack-dev-server or @rspack/dev-server, but implement DevServer based on webpack-dev-middleware.
Deprecated: This configuration is deprecated, please use dev.setupMiddlewares instead.
Array
[]
Provides the ability to execute custom middleware after all other middleware internally within the server.
webpack-dev-server
uses Express as the server-side framework. Modern.js does not use any framework, and the req
and res
in the above middleware are all native Node objects. Therefore, the Express middleware used in webpack-dev-server
may not be directly usable in Modern.js.
If you want to migrate the Express middleware used in webpack-dev-server
, you can use the following method to pass the Express app as middleware:
Deprecated: This configuration is deprecated, please use dev.setupMiddlewares instead.
Array
[]
Provides the ability to execute custom middleware prior to all other middleware internally within the server.
Deprecated: This configuration is deprecated, please use dev.client instead.
The config of HMR client, which are usually used to set the WebSocket URL of HMR.
boolean
true
Whether to enable gzip compression for served static assets.
If you want to disable the gzip compression, you can set compress
to false
:
Deprecated: This configuration is deprecated, please use dev.writeToDisk instead.
The config of devMiddleware. Current options is the subset of webpack-dev-middleware.
Record<string, string>
undefined
Adds headers to all responses.
boolean | ConnectHistoryApiFallbackOptions
false
The index.html page will likely have to be served in place of any 404 responses. Enable devServer.historyApiFallback
by setting it to true
:
For more options and information, see the connect-history-api-fallback documentation.
Deprecated: This configuration is deprecated, please use dev.hmr instead.
boolean
true
Enable Hot Module Replacement feature.
Deprecated: This configuration is deprecated, please use dev.https instead.
boolean | { key: string; cert: string }
false
By default, DevServer will be served over HTTP. It can optionally be served over HTTPS by setting devServer.https
to true
, and will disable the HTTP server.
You can also manually pass in the certificate and corresponding private key required by the HTTPS server:
Deprecated: This configuration is deprecated, please use dev.liveReload instead.
boolean
true
By default, the DevServer will reload/refresh the page when file changes are detected (devServer.hot
option must be disabled in order for liveReload to take effect). Disable devServer.liveReload
by setting it to false
.
Deprecated: This configuration is deprecated, please use dev.setupMiddlewares instead.
undefined
Provides the ability to execute a custom function and apply custom middlewares.
The order among several different types of middleware is: devServer.before
=> unshift
=> internal middlewares => push
=> devServer.after
.
It is possible to use some server api to meet special scenario requirements:
Record<string, string> | Record<string, ProxyDetail>
undefined
Proxying some URLs.
A request to /api/users will now proxy the request to http://localhost:3000/api/users.
If you don't want /api to be passed along, we need to rewrite the path:
The DevServer Proxy makes use of the http-proxy-middleware package. Check out its documentation for more advanced usages.
The full type definition of DevServer Proxy is:
In addition to the http-proxy-middleware option, we also support the bypass and context configuration:
null
or undefined
to continue processing the request with proxy.false
to produce a 404 error for the request.boolean
true
Whether to watch files change in directories such as mock/
, server/
, api/
.