> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# output

Options for build outputs.

## output.assetPrefix [![output.assetPrefix](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.assetPrefix](https://rsbuild.rs/config/output/asset-prefix)
Use this option to set the URL prefix for static assets, such as setting it to a CDN URL.

In Rslib, the default value for this option depends on [format](/config/lib/format.md):

- When `format` is `cjs` or `esm`, the default value is `"auto"`.
- When `format` is `mf`, `umd`, or `iife`, the default value is `"/"`.

When `output.assetPrefix` is set to `"auto"`, Rslib defaults to setting [importMode](https://rspack.rs/config/module-generator#assetimportmode) to `"preserve"`, which preserves the `import` or `require` statements for static assets in JavaScript files. Additionally, the static asset references in CSS files remain as relative paths, see [Static assets](/guide/advanced/static-assets.md) for more details.

When `output.assetPrefix` is set to a specific path, the static asset import statements in JavaScript files will no longer be preserved and will be replaced with URLs prefixed by that path. Additionally, the static asset paths in CSS files will be substituted with paths that include this prefix.

## output.autoExternal [![output.autoExternal](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.autoExternal](https://rsbuild.rs/config/output/auto-external)
- **CLI:** `--auto-external` / `--no-auto-external`

Whether to automatically externalize dependencies of different dependency types and do not bundle them. This is a specific configuration for bundle mode, it will not take effect in bundleless mode.

In Rslib, the default value for this option depends on [format](/config/lib/format.md):

- When `format` is `cjs` or `esm`, the default value is `true`.
- When `format` is `umd`, `mf`, or `iife`, the default value is `false`.

When set to `true`, the `dependencies`, `optionalDependencies`, and `peerDependencies` listed in `package.json` will be automatically externalized.

For more details about handling third-party dependencies, please refer to [Handle Third-party Dependencies](/guide/advanced/third-party-deps.md).

## output.charset [![output.charset](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.charset](https://rsbuild.rs/config/output/charset)
The `charset` config allows you to specify the [character encoding](https://developer.mozilla.org/en-US/docs/Glossary/Character_encoding) for output files to ensure they are displayed correctly in different environments.

## output.cleanDistPath [![output.cleanDistPath](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.cleanDistPath](https://rsbuild.rs/config/output/clean-dist-path)
- **CLI:** `--clean` / `--no-clean`

Whether to clean up all files under the output directory before the build starts (the output directory defaults to `dist`).

## output.copy [![output.copy](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.copy](https://rsbuild.rs/config/output/copy)
Copies the specified file or directory to the dist directory, implemented based on [rspack.CopyRspackPlugin](https://rspack.rs/plugins/rspack/copy-rspack-plugin).

## output.cssModules [![output.cssModules](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.cssModules](https://rsbuild.rs/config/output/css-modules)
For custom CSS Modules configuration.

## output.dataUriLimit [![output.dataUriLimit](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.dataUriLimit](https://rsbuild.rs/config/output/data-uri-limit)
Set the size threshold to inline static assets such as images and fonts.

When [format](/config/lib/format.md) is set to `cjs` or `esm`, Rslib defaults to setting `output.dataUriLimit` to `0`, without inlining any static assets, so that build tools on the application side can handle and optimize them.

## output.distPath [![output.distPath](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.distPath](https://rsbuild.rs/config/output/dist-path)
- **CLI:** `--dist-path <dir>` (e.g. `--dist-path output`)

Set the directory of the dist files. Rsbuild will output files to the corresponding subdirectory according to the file type.

By default, Rslib sets `output.distPath` to:

```ts
const defaultDistPath = {
  root: 'dist',
  js: './',
  jsAsync: './',
  css: './',
  cssAsync: './',
  svg: 'static/svg',
  font: 'static/font',
  wasm: 'static/wasm',
  image: 'static/image',
  media: 'static/media',
  assets: 'static/assets',
};
```

The `wasm` option only takes effect when [lib.wasm.mode](/config/lib/wasm.md#wasmmode) is `compile`, and specifies the output directory for `.wasm` files. In `preserve` mode, `.wasm` files are emitted at their source-relative paths.



## output.emitCss [![output.emitCss](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.emitCss](https://rsbuild.rs/config/output/emit-css)
Whether to emit CSS to the output bundles.

## output.externals [![output.externals](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.externals](https://rsbuild.rs/config/output/externals)
- **CLI:** `--externals <pkg>` (repeatable, e.g. `--externals react --externals react-dom`)

At build time, prevent some `import` dependencies from being packed into bundles in your code, and instead fetch them externally at runtime.

In bundle mode, Rslib will automatically externalize the dependencies listed in `package.json` based on [output.autoExternal](#outputautoexternal). See [output.autoExternal](#outputautoexternal) for more information.

In addition, Rslib sets the default Rspack [`externalsType`](https://rspack.rs/config/externals#externalstype) based on the output format:

- `esm`: [modern-module](https://rspack.rs/config/externals#externalstypemodern-module). Static `import` externals are emitted as ESM imports, and dynamic `import()` externals stay dynamic. CommonJS `require()` externals load through `createRequire` for Node-like [`output.target`](#outputtarget) values, while other targets preserve a bare `require()` call.

:::warning
When external modules are loaded through `createRequire()`, bundling the output again requires the consuming bundler to statically analyze this call pattern. Rspack users can enable [`module.parser.javascript.createRequire`](https://rspack.rs/config/module-parser#javascriptcreaterequire) to support it.
:::

- `cjs`: [commonjs-import](https://rspack.rs/config/externals#externalstypecommonjs-import).
- `umd`: [umd](https://rspack.rs/config/externals#externalstype).
- `mf` / `iife`: [global](https://rspack.rs/config/externals#externalstypeglobal).

:::note
It is important to note that `output.externals` differs from [resolve.alias](/config/rsbuild/resolve.md#resolvealias). Check out [resolve.alias](/config/rsbuild/resolve.md#resolvealias) documentation for more information.
:::

## output.filenameHash [![output.filenameHash](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.filenameHash](https://rsbuild.rs/config/output/filename-hash)
Whether to add a hash value to the filename after the production build.

Rslib sets `output.filenameHash` to `false` for `esm`, `cjs`, `umd`, and `iife` formats. For `mf`, Rslib retains Rsbuild's default, which adds hash values to output filenames in production mode.

::: info Filename hash

Set `output.filenameHash` to `true` to add hash values to output filenames, or `false` to disable this behavior.

You can also specify different filenames for different types of files by configuring `output.filename`.

:::

## output.filename [![output.filename](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.filename](https://rsbuild.rs/config/output/filename)
Sets the filename of dist files.

By default, Rslib will modify the JavaScript output file extension by setting `output.filename.js` according to [format](/config/lib/format.md), see [autoExtension](/config/lib/auto-extension.md) for more details.

## output.injectStyles [![output.injectStyles](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.injectStyles](https://rsbuild.rs/config/output/inject-styles)
Whether to inject styles into DOM.

## output.inlineScripts [![output.inlineScripts](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.inlineScripts](https://rsbuild.rs/config/output/inline-scripts)
Whether to inline output scripts files (.js files) into HTML with `<script>` tags.

## output.inlineStyles [![output.inlineStyles](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.inlineStyles](https://rsbuild.rs/config/output/inline-styles)
Whether to inline output style files (.css files) into HTML with `<style>` tags.

## output.legalComments [![output.legalComments](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.legalComments](https://rsbuild.rs/config/output/legal-comments)
Configure how to handle the legal comment.

## output.manifest [![output.manifest](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.manifest](https://rsbuild.rs/config/output/manifest)
Whether to generate a manifest file that contains information of all assets, and the mapping relationship between [entry module](https://rsbuild.rs/config/source/entry) and assets.

## output.minify [![output.minify](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.minify](https://rsbuild.rs/config/output/minify)
- **CLI:** `--minify` / `--no-minify`

Configure whether to enable code minification, or to configure minimizer options.

When `output.minify` is not specified, Rslib will use a sane default value.

- When format is `esm` or `cjs`, only dead code elimination and unused code elimination will be performed. The default value is:

```ts
export default defineConfig({
  output: {
    minify: {
      js: true,
      css: false,
      jsOptions: {
        minimizerOptions: {
          mangle: false,
          minify: false,
          compress: {
            defaults: false,
            directives: false,
            unused: true,
            dead_code: true,
            toplevel: true,
          },
          format: {
            comments: 'some',
            preserve_annotations: true,
          },
        },
      },
    },
  },
});
```

- When format is `umd`, the default value is the same as above, only dead code elimination and unused code elimination will be performed, which is usually used to generate UMD output for development. If you need to generate UMD output for production with the smallest possible bundle size, you can set `output.minify` to true:

```ts
export default defineConfig({
  output: {
    minify: true,
  },
});
```

- When format is `iife`, Rslib also only performs dead code elimination and unused code elimination by default, with `minimizerOptions.module` set to `true`.

- When format is `mf`, since MF assets are loaded over the network, which means they will not be compressed by the application project. Therefore, they need to be minified in Rslib. The default value is:

```ts
export default defineConfig({
  output: {
    minify: {
      js: true,
      css: false,
      jsOptions: {
        minimizerOptions: {
          mangle: false,
          // Enable minification
          minify: true,
          compress: {
            defaults: false,
            directives: false,
            unused: true,
            dead_code: true,
            // Avoid remoteEntry's global variable being tree-shaken
            toplevel: false,
          },
          format: {
            comments: 'some',
            preserve_annotations: true,
          },
        },
      },
    },
  },
});
```

::: note

It should be noted that the `output.minify` option you configured will completely override the above default configuration.

:::

## output.overrideBrowserslist [![output.overrideBrowserslist](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.overrideBrowserslist](https://rsbuild.rs/config/output/override-browserslist)
Specifies the range of target browsers that the project is compatible with.

Rslib will generate `output.overrideBrowserslist` based on [syntax](/config/lib/syntax.md), see [ESX\_TO\_BROWSERSLIST](https://github.com/web-infra-dev/rslib/blob/8d65f3728d60254bcf1a8e24d72902ad79dae959/packages/core/src/utils/syntax.ts#L42-L153) to get the mapping value.

## output.polyfill [![output.polyfill](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.polyfill](https://rsbuild.rs/config/output/polyfill)
Through the `output.polyfill` option, you can control the injection mode of the polyfills.

:::warning
Rsbuild's `output.polyfill` injects polyfills into the global scope, which can unexpectedly modify global variables for library consumers. For a non-global polyfill solution for browsers, please refer to [Polyfill - Browser](/guide/advanced/output-compatibility.md#browser).
:::

## output.sourceMap [![output.sourceMap](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.sourceMap](https://rsbuild.rs/config/output/source-map)
Used to set whether to generate source map files, and which format of source map to generate.

## output.target [![output.target](https://assets.rspack.rs/rsbuild/rsbuild-logo.svg)output.target](https://rsbuild.rs/config/output/target)
- **CLI:** `--target <target>` (e.g. `--target web`)

Setting the build target of Rsbuild.

Rslib sets `output.target` to `node` by default for `esm`, `cjs`, `umd`, and `iife` formats, and to `web` for `mf`.

:::info
Check out the [Solution](/guide/solution/index.md) to learn more about the build target.
:::
