For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/configure/app/tools/dev-server.md.
  • 简体中文
  • tools.devServer

    • 类型: Object
    • 默认值: {}

    通过 tools.devServer 可以修改开发环境服务器的配置。

    选项

    compress

    Warning

    Deprecated:该配置已废弃,请使用 dev.server.compress 代替。

    • 类型: boolean
    • 默认值: true

    是否对静态资源启用 gzip 压缩。

    如果你需要禁用 gzip 压缩,可以将 compress 设置为 false:

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

    headers

    Warning

    Deprecated:该配置已废弃,请使用 dev.server.headers 代替。

    • 类型: Record<string, string>
    • 默认值: undefined

    设置自定义响应头。

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

    historyApiFallback

    Warning

    Deprecated:该配置已废弃,请使用 dev.server.historyApiFallback 代替。

    • 类型: boolean | ConnectHistoryApiFallbackOptions
    • 默认值: false

    在需要对一些 404 响应或其他请求提供替代页面的场景,可通过 devServer.historyApiFallback 进行设置:

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

    更多选项和详细信息可参考 connect-history-api-fallback 文档。

    proxy

    Warning

    Deprecated:该配置已废弃,请使用 dev.server.proxy 代替。

    • 类型: ProxyOptions[] | Record<string, string | ProxyOptions>
    • 默认值: undefined

    为开发服务器配置代理规则,把请求转发到指定服务。

    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:该配置已废弃,请使用 dev.server.watch 代替。

    • 类型: boolean
    • 默认值: true

    是否监听 mock/、server/、api/ 等目录的文件变化。