For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /config/performance/print-file-size.md.
close

performance.printFileSize

  • Type:
type PrintFileSizeOptions =
  | boolean
  | {
      total?: boolean | Function;
      detail?: boolean;
      compressed?: boolean | { type?: 'gzip' | 'brotli'; level?: number };
      include?: (asset: PrintFileSizeAsset) => boolean;
      exclude?: (asset: PrintFileSizeAsset) => boolean;
      diff?: boolean;
    };
  • Default: true

Whether to print the file sizes after production build.

Default outputs

The default output log is as follows:

File (web)                                Size        Gzip
dist/static/js/lib-react.b0714b60ab.js    140.4 kB    45.0 kB
dist/static/js/index.f3fde9c7ab.js        1.9 kB      0.97 kB
dist/index.html                           0.39 kB     0.25 kB
dist/static/css/index.2960ac62ab.css      0.35 kB     0.26 kB

                                 Total:   143.0 kB    46.3 kB

Disable outputs

If you do not want to print any information, you can disable it by setting printFileSize to false:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: false,
  },
};

Options

You can customize the output format through the options.

total

  • Type:
type Total =
  | boolean
  | ((params: {
      environmentName: string;
      distPath: string;
      assets: PrintFileSizeAsset[];
      totalSize: number;
      totalGzipSize: number;
      totalBrotliSize?: number;
    }) => string);
  • Default: true

Whether to output the total size of all static assets, or provide a function to customize the output format of the total size.

When set to false, the total size will not be output:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      total: false,
    },
  },
};
Tip

If the current build only generates one static asset, the total size will not be printed.

When set to a function, you can customize the total size output format:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      total: ({ distPath, assets, totalSize }) => {
        return `Generated ${assets.length} files in ${distPath}, the total size is ${(totalSize / 1000).toFixed(1)} kB.`;
      },
    },
  },
};

Function parameters:

  • environmentName: The unique name of the current environment, used to distinguish and locate the environment
  • distPath: The output directory relative to the project root
  • assets: Array of static assets, each containing name and size properties
  • totalSize: Total size of all static assets in bytes
  • totalGzipSize: Total gzip-compressed size of all static assets in bytes. Set to 0 when gzip size reporting is disabled.
  • totalBrotliSize: Total Brotli-compressed size of all static assets in bytes. Set to undefined when Brotli size reporting is disabled.

detail

  • Type: boolean
  • Default: true

Whether to output the size of each static asset.

If you do not need to view the size of each static asset, you can set detail to false. In this case, only the total size will be output:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      detail: false,
    },
  },
};

compressed

  • Type: boolean | { type?: 'gzip' | 'brotli'; level?: number }
  • Default: false when output.target is node, otherwise true

Controls whether to calculate and print compressed asset sizes after a build. Set to true to report gzip sizes, false to skip compression calculations, or an object to configure the algorithm and level.

Calculating compressed sizes adds to build time. If you do not need compressed size reporting, set compressed to false to skip these calculations:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      compressed: false,
    },
  },
};
Tip
  • This option only reports sizes; it does not generate compressed files. To serve compressed assets, you typically need to configure compression on your server or CDN. Actual transfer sizes depend on those compression settings.
  • For non-compressible assets (such as images), the compressed size is not shown in the detailed list, but their original size is included in the total compressed size.
  • When diff is enabled, Rsbuild compares compressed sizes only when both builds use the same algorithm. Changes caused by adjusting level are included in the compressed size diff. Comparisons of uncompressed sizes are unaffected by these settings.

type

  • Type: 'gzip' | 'brotli'
  • Default: 'gzip'

Selects the compression algorithm used to calculate asset sizes:

ValueBehavior
'gzip'Report gzip sizes in the Gzip column.
'brotli'Report Brotli sizes in the Br column.

For example, to report Brotli sizes:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      compressed: {
        type: 'brotli',
      },
    },
  },
};

Brotli can take longer than gzip, especially when the build produces many assets or large files.

level

  • Type: number
  • Default: 6

Sets the compression level. The valid range depends on the algorithm:

  • gzip: An integer from 0 to 9.
  • Brotli: An integer from 0 to 11, corresponding to Brotli's quality parameter.

For example, use Brotli's highest level to estimate the size of assets precompressed at level 11:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      compressed: {
        type: 'brotli',
        level: 11,
      },
    },
  },
};

Higher levels generally produce smaller files but take longer to calculate. Brotli level 11 can be particularly slow. To estimate production transfer sizes, use the same algorithm and level as your server or CDN.

include

  • Type:
type PrintFileSizeAsset = {
  /**
   * The name of the static asset.
   * @example 'index.html', 'static/js/index.[hash].js'
   */
  name: string;
  /**
   * The size of the static asset in bytes.
   */
  size: number;
};
type Include = (asset: PrintFileSizeAsset) => boolean;
  • Default: undefined

A filter function to determine which static assets to print.

If returned false, the static asset will be excluded and not included in the total size or detailed size.

For example, only output static assets larger than 10 kB:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      include: (asset) => asset.size > 10 * 1000,
    },
  },
};

Or only output .js files larger than 10 kB:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      include: (asset) => /\.js$/.test(asset.name) && asset.size > 10 * 1000,
    },
  },
};

exclude

  • Type:
type Exclude = (asset: PrintFileSizeAsset) => boolean;
  • Default: (asset) => /\.(?:map|LICENSE\.txt|d\.(?:ts|mts|cts))$/.test(asset.name)

A filter function to determine which static assets to exclude. If both include and exclude are set, exclude will take precedence.

Rsbuild defaults to excluding source map, license files, and .d.ts, .d.mts, or .d.cts type declaration files, as these files do not affect page load performance.

For example, exclude .html files in addition to the default:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      exclude: (asset) =>
        /\.(?:map|LICENSE\.txt|d\.(?:ts|mts|cts))$/.test(asset.name) ||
        /\.html$/.test(asset.name),
    },
  },
};

diff

  • Type: boolean
  • Default: false

Controls whether file size differences are displayed relative to the previous build.

When this option is enabled, Rsbuild records a snapshot of all output file sizes after each build. On subsequent builds, Rsbuild compares the current sizes against the previous snapshot and shows the change inline in parentheses.

To enable diff output:

rsbuild.config.ts
export default {
  performance: {
    printFileSize: {
      diff: true,
    },
  },
};

On the second build, the output begins to include inline size deltas:

File (web)                                Size                  Gzip
dist/static/js/lib-react.b0714b60ab.js    140.4 kB (+2.1 kB)    45.0 kB (+0.5 kB)
dist/static/js/index.f3fde9c7ab.js        1.9 kB (-0.3 kB)      0.97 kB (-0.1 kB)
dist/static/css/index.2960ac62ab.css      0.35 kB (+0.35 kB)    0.26 kB (+0.26 kB)

                                 Total:   143.0 kB (+2.15 kB)   46.3 kB (+0.66 kB)
  • Increases are highlighted in red with a + prefix
  • Decreases are highlighted in green with a - prefix
  • Files with no change omit the diff indicator
Tip

Snapshots are stored at <root>/node_modules/.cache/rsbuild/file-sizes-[hash].json, where [hash] is derived from the Rsbuild configuration file path.

Version history

VersionChanges
v2.2.5Added compressed.type and compressed.level options to select the compression algorithm and level
v1.6.13Added diff option