tools.devServer

  • Type: Object
  • Default: {}

The config of DevServer can be modified through tools.devServer.

Tip

Modern.js does not directly use webpack-dev-server or @rspack/dev-server, but implement DevServer based on webpack-dev-middleware.

Options

compress

Warning

Deprecated: This configuration is deprecated, please use dev.server.compress instead.

  • Type: boolean
  • Default: true

Whether to enable gzip compression for served static assets.

If you want to disable the gzip compression, you can set compress to false:

export default {
  tools: {
    devServer: {
      compress: false,
    },
  },
};

headers

Warning

Deprecated: This configuration is deprecated, please use dev.server.headers instead.

  • Type: Record<string, string>
  • Default: undefined

Adds headers to all responses.

export default {
  tools: {
    devServer: {
      headers: {
        'X-Custom-Foo': 'bar',
      },
    },
  },
};

historyApiFallback

Warning

Deprecated: This configuration is deprecated, please use dev.server.historyApiFallback instead.

  • Type: boolean | ConnectHistoryApiFallbackOptions
  • Default: 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:

export default {
  tools: {
    devServer: {
      historyApiFallback: true,
    },
  },
};

For more options and information, see the connect-history-api-fallback documentation.

proxy

Warning

Deprecated: This configuration is deprecated, use dev.server.proxy instead.

  • Type: ProxyOptions[] | Record<string, string | ProxyOptions>
  • Default: undefined

Configure proxy rules for the dev server, and forward requests to the specified service.

export default {
  tools: {
    devServer: {
      proxy: {
        // http://localhost:8080/api -> https://example.com/api
        // http://localhost:8080/api/foo -> https://example.com/api/foo
        '/api': 'https://example.com',
      },
    },
  },
};

watch

Warning

Deprecated: This configuration is deprecated, please use dev.server.watch instead.

  • Type: boolean
  • Default: true

Whether to watch files change in directories such as mock/, server/, api/.