dev.server

  • Type: Object
  • Default: {}

The config of DevServer can be modified through dev.server.

compress

  • 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 {
  dev: {
    server: {
      compress: false,
    },
  },
};

For more details, please refer to the Rsbuild - server.compress documentation.

headers

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

Adds headers to all responses.

export default {
  dev: {
    server: {
      headers: {
        'X-Custom-Foo': 'bar',
      },
    },
  },
};

For more details, please refer to the Rsbuild - server.headers documentation.

historyApiFallback

  • Type: boolean | ConnectHistoryApiFallbackOptions
  • Default: false

The index.html page will likely have to be served in place of any 404 responses. Enable dev.server.historyApiFallback by setting it to true:

export default {
  dev: {
    server: {
      historyApiFallback: true,
    },
  },
};

For more configuration options, please refer to the Rsbuild - server.historyApiFallback documentation.

watch

  • Type: boolean
  • Default: true

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

For more details, please refer to the Rsbuild - dev.watchFiles documentation.

cors

  • Type: boolean | import('cors').CorsOptions

Configure CORS (Cross-Origin Resource Sharing) for the development server.

The default configuration for cors in Modern.js follows Rsbuild's defaults:

const defaultAllowedOrigins =
  /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;

const defaultOptions = {
  // Default allowed:
  // - localhost
  // - 127.0.0.1
  // - [::1]
  origin: defaultAllowedOrigins,
};

For more configuration options and detailed usage, please refer to the Rsbuild - server.cors documentation.

proxy

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

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

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

This option is the same as Rsbuild's server.proxy option, see Rsbuild - server.proxy for detailed usage.