exports
- Type:
- Default:
false - CLI:
--exports/--no-exports - Top-level config: Only supported at the top level
Generates the exports field in package.json from the build outputs after the build completes.
The generated result overwrites the existing exports and publishConfig.exports fields in package.json. To keep handwritten subpaths, add them with exports.custom.
Rslib does not generate the exports field in watch mode, or when only some libs are built with --lib.
Generation rules
- Only ESM and CJS outputs can be exported.
- The
indexentry is exported as.,button/indexas./button, and other entries by their names. - If an entry has both ESM and CJS outputs, they are distinguished by the
importandrequireconditions. If it has only one format, the output path is used directly. - When dts is enabled, a
typescondition is added if TypeScript cannot find the declaration files from the output paths. - In bundle mode, the CSS files generated for the entries are also exported.
The following example shows the result for a library that builds both ESM and CJS outputs:
exports.include
- Type:
string[] - Default: all entries are exported in bundle mode, and only
indexis exported in bundleless mode
Selects the outputs to export. The glob patterns are matched against the output paths relative to the output directory, and the extension can be omitted.
For example, to export the index files in the root directory and in each component directory in bundleless mode:
exports.exclude
- Type:
string[] - Default:
[]
Excludes some of the outputs matched by include. The patterns are written in the same way as include.
For example, to export the index files in each directory except the internal directory in bundleless mode:
exports.source
- Type:
boolean | string - Default:
false
Exports the source files of the entries, so that the source code can be referenced directly during development.
- When set to
true,exportspoints to the source files, and the exports pointing to the build outputs are written topublishConfig.exports. - When set to a string, a condition named after the string and pointing to the source file is added to each JavaScript subpath. It can be used with the customConditions option of TypeScript or @rsbuild/plugin-source-build.
For example, source: '@scope/source' generates:
exports.custom
- Type:
- Default:
undefined
Customizes the generated exports.
- When an object is passed, its subpaths are added to the generated result, and subpaths with the same name are replaced.
- When a function is passed, it receives the generated exports and returns the final result. When
sourceistrue,exportsandpublishConfig.exportsare each passed through the function, and you can tell them apart byisPublishConfigin the second argument. - When an array is passed, its items are applied in order.
For example, to add the ./package.json subpath:
Use a function to modify the generated subpaths, for example, to add a browser condition to .:
