close
  • 简体中文
  • server.base

    • 类型: string
    • 默认值: /
    • 版本: >= 1.0.10

    server.base 用于配置服务器的 基础路径

    示例

    默认情况下,Rsbuild 服务器的基础路径是 /,你可以通过 http://localhost:3000/ 访问 index.html 等输出文件,以及 public 目录 下的资源。

    当你希望通过 http://localhost:3000/foo/ 访问到 index.html 时,可以将 server.base 修改为 /foo

    rsbuild.config.ts
    export default {
      server: {
        base: '/foo',
      },
    };

    静态资源 URL 前缀

    dev.assetPrefixoutput.assetPrefix 会读取 server.base 的值作为默认值。

    server.base/foo 时,默认在浏览器中加载的资源 URL 如下:

    <script defer src="/foo/static/js/index.js"></script>

    此时,可以通过 http://localhost:3000/foo/ 访问到 index.html 以及其他静态资源产物。

    如果你不希望使用此默认行为,可以通过显式设置 dev.assetPrefix / output.assetPrefix 来覆盖:

    rsbuild.config.ts
    export default {
      dev: {
        assetPrefix: '/',
      },
      output: {
        assetPrefix: 'https://cdn.example.com/assets/',
      },
      server: {
        base: '/foo',
      },
    };