For AI agents: the complete documentation index is available at https://rsbuild.rs/llms.txt, the full documentation bundle is available at https://rsbuild.rs/llms-full.txt, and this page is available as Markdown at https://rsbuild.rs/config/server/serve-assets.md.
close

server.serveAssets

  • Type: boolean
  • Default: true when output.target is web or web-worker, false when it is node

Controls whether Rsbuild's dev and preview servers serve build output over HTTP, including JavaScript, CSS, HTML, and source maps.

Set this option to false to stop serving build output over HTTP:

rsbuild.config.ts
export default {
  server: {
    serveAssets: false,
  },
};

Setting this option to false does not affect compilation, file watching, or writing output to disk. You can still access the output through the dev server's loadBundle and getTransformedHtml APIs.

You can also use server.setup to add custom routes that handle HTTP requests for build output.

Multiple environments

Each environment inherits the top-level server.serveAssets value and can override it with its own setting. If neither is set, the default depends on that environment's output.target.

For example, disable HTTP serving of a Worker's output while continuing to serve browser assets:

rsbuild.config.ts
export default {
  environments: {
    web: {
      output: {
        distPath: 'dist/client',
      },
    },
    worker: {
      server: {
        serveAssets: false,
      },
      output: {
        target: 'web-worker',
        distPath: 'dist/worker',
      },
    },
  },
};

Public directories

Files in public directories are managed by server.publicDir:

  • Development: the dev server serves public directories independently of serveAssets. To stop serving public files as well, set server.publicDir: false.
  • Build and preview: publicDir.copyOnBuild still controls whether files are copied to the output directory. The preview server treats these copies as build output, so serveAssets controls whether they are served.

Overlapping output directories

When environments share an output directory, or one output directory contains another, an environment with serveAssets: true can also serve files from an environment with serveAssets: false.

For example, an environment serving dist can also serve files in dist/worker, even if the Worker environment sets serveAssets: false. Use separate directories such as dist/client and dist/worker when environments have different serveAssets settings.

Version history

VersionChanges
v2.3.2Added server.serveAssets.