Bundleless means that each source file is compiled and built separately, which can be understood as the process of code transformation of source files only. To skip the preprocessing of .less/.scss files, you need to:
source.entry to remove .less/.scss files from the entry.output.copy to copy .less/.scss files to the output directory.redirect.style.extension to false to disable the redirect behavior for the import path of .less/.scss files.Below is an example of skipping the .scss file processing. All .scss files in src will be copied to the output directory and retained with consistent relative paths.
In bundleless mode, Rslib transforms the source static asset file into a JavaScript file and a static asset file that is emitted according to output.distPath by default, while preserving the import or require statements for static assets. To skip the above processing of static asset files, you need to:
source.entry to remove static asset files from the entry.output.copy to copy static asset files to the output directory.redirect.asset.extension to false to disable the redirect behavior for the import path of static asset files.Below is an example of skipping the .png file processing. All .png files in src will be copied to the output directory and retained with consistent relative paths.
By default, Rslib uses SWC to remove comments. The corresponding SWC jsc.minify.format configuration is
This will only preserve some legal comments and annotations. If you want to preserve all comments, you can refer to the following configuration:
Compressing code can reduce the output size and improve loading speed, but the compressed code is less readable and harder to debug. If you want to preserve code readability, you can keep variable names and disable compression to facilitate debugging. Refer to web-infra-dev/rsbuild#966.
As shown below, Rslib ignores the files under the src/tests directory when emitting JavaScript outputs, but these files still generate corresponding declaration files.
The entry set by source.entry can exclude some files that do not generate corresponding JavaScript outputs, but cannot exclude the generation of corresponding declaration files. This needs to be achieved by setting include and exclude in tsconfig.json, as shown below:
If you want to keep type prompts and checking for these files, but do not generate corresponding declaration files, you can inherit a basic tsconfig.json by extends and then override the include and exclude options as follows:
The newly added tsconfig.build.json needs to be configured in the source.tsconfigPath option in rslib.config.ts:
dts.bundle is true?Rslib uses rsbuild-plugin-dts to generate declaration files, which supports configuration via output.externals for excluding certain dependencies from bundled declaration files.
For example, a typical React component library often does not declare @types/react in peerDependencies but only in devDependencies. Following the autoExternal logic for dependency handling, Rslib will attempt to bundle @types/react into the declaration output files during the build. However, in practice, a component library should not bundle @types/react.
In this scenario, you can configure output.externals to exclude @types/react.
modifyRsbuildConfig to modify the configuration does not take effect?Rslib internally generates Rsbuild's environments configurations, and each configuration item in the lib array corresponds to a specific environment configuration.
modifyRsbuildConfig is a global hook that cannot be effective for configurations under a specific environment. It is usually used in Rslib to modify globally effective plugins, etc. Therefore, you need to use modifyEnvironmentConfig instead to modify the configuration of a specific environment.
Refer to Environment Plugin to learn how to develop an Environment Plugin.
__webpack_hash__ in the source code when generating outputs?Rslib based on Rspack will transform module variables like __webpack_hash__, __webpack_nonce__, __webpack_public_path__, etc. to runtime code containing __webpack_require__ by default during build process. If you need to preserve these module variables in the outputs, you can configure source.define as follows:
__webpack_hash__ with WEBPACK_HASH, __webpack_nonce__ with WEBPACK_NONCE, __webpack_public_path__ with WEBPACK_PUBLIC_PATH, etc.source.define. The key of the passed configuration object is the replaced variable name in the source code, and the value is the module variable that needs to be preserved in the outputs.