output

Options for build outputs.

output.charset output.charsetoutput.charset

The charset config allows you to specify the character encoding for output files to ensure they are displayed correctly in different environments.

output.cleanDistPath output.cleanDistPathoutput.cleanDistPath

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

output.copy output.copyoutput.copy

Copies the specified file or directory to the dist directory, implemented based on rspack.CopyRspackPlugin.

output.cssModules output.cssModulesoutput.cssModules

For custom CSS Modules configuration.

output.dataUriLimit output.dataUriLimitoutput.dataUriLimit

Set the size threshold to inline static assets such as images and fonts.

output.distPath output.distPathoutput.distPath

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:

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',
};

output.emitCss output.emitCssoutput.emitCss

Whether to emit CSS to the output bundles.

output.externals output.externalsoutput.externals

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 add the dependencies listed in the dependencies, optionalDependencies, and peerDependencies fields of package.json to output.externals. See lib.autoExternal for more information.

NOTE

It is important to note that output.externals differs from resolve.alias. Check out resolve.alias documentation for more information.

output.filenameHash output.filenameHashoutput.filenameHash

Whether to add a hash value to the filename after the production build.

Rslib sets output.filenameHash to false by default.

output.filename output.filenameoutput.filename

Sets the filename of dist files.

By default, Rslib sets output.filename based on format, see autoExtension for more information.

output.inlineScripts output.inlineScriptsoutput.inlineScripts

Whether to inline output scripts files (.js files) into HTML with <script> tags.

output.inlineStyles output.inlineStylesoutput.inlineStyles

Whether to inline output style files (.css files) into HTML with <style> tags.

output.legalComments output.legalCommentsoutput.legalComments

Configure how to handle the legal comment.

output.manifest output.manifestoutput.manifest

Whether to generate a manifest file that contains information of all assets, and the mapping relationship between entry module and assets.

output.minify output.minifyoutput.minify

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

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

  • When format is esm, cjs and umd, only dead code elimination and unused code elimination will be performed. The default value is:
export default defineConfig({
  output: {
    minify: {
      js: true,
      css: false,
      jsOptions: {
        minimizerOptions: {
          mangle: false,
          minify: false,
          compress: {
            defaults: false,
            unused: true,
            dead_code: true,
            toplevel: true,
          },
          format: {
            comments: 'some',
            preserve_annotations: 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:
export default defineConfig({
  output: {
    minify: {
      js: true,
      css: false,
      jsOptions: {
        minimizerOptions: {
          mangle: false,
          // Enable minification
          minify: true,
          compress: {
            defaults: false,
            unused: true,
            dead_code: true,
            // Avoid remoteEntry's global variable being tree-shaken
            toplevel: false,
          },
          format: {
            comments: 'some',
            preserve_annotations: true,
          },
        },
      },
    },
  },
});

output.overrideBrowserslist output.overrideBrowserslistoutput.overrideBrowserslist

Specifies the range of target browsers that the project is compatible with.

Rslib will generate output.overrideBrowserslist based on syntax, see ESX_TO_BROWSERSLIST to get the mapping value.

output.polyfill output.polyfilloutput.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.

output.sourceMap output.sourceMapoutput.sourceMap

Used to set whether to generate source map files, and which format of source map to generate.

output.target output.targetoutput.target

Setting the build target of Rsbuild.

Rslib sets output.target to node by default.

INFO

Check out the Solution to learn more about the build target.