close
logo
Rslib
指南
配置
博客
English
简体中文
指南
配置
博客
English
简体中文
logo
Rslib
配置总览

Lib 配置

lib.format
lib.bundle
lib.autoExtension
lib.autoExternal
lib.redirect
lib.syntax
lib.externalHelpers
lib.banner
lib.footer
lib.dts
lib.shims
lib.id
lib.umdName
lib.outBase

Rsbuild 配置

logLevel
resolve
source
output
tools
plugins
📝 在 GitHub 上编辑此页
上一页resolve
下一页output

#source

与输入的源代码相关的选项。

#source.assetsInclude source.includesource.include

指定需要被视为静态资源的额外文件类型。

#source.decorators source.decoratorssource.decorators

用于配置装饰器语法。

如果在 tsconfig.json 中启用了 experimentalDecorators,Rslib 会默认将 source.decorators.version 设置为 legacy。

#source.define source.definesource.define

构建时将代码中的变量替换成其它值或者表达式,可以用于在构建时向代码注入环境变量等信息。

#source.entry source.entrysource.entry

用于设置构建的入口模块。

在 Rslib 中,默认值为:

  • bundle 模式:
const defaultEntry = {
  // 默认支持其他后缀,如 ts、tsx、jsx、mjs、cjs
  index: 'src/index.js',
};
  • bundleless 模式:
const defaultEntry = {
  index: 'src/**',
};
INFO

参考 lib.bundle 进一步了解如何为 bundle 和 bundleless 项目设置入口。

#source.exclude source.excludesource.exclude

排除不需要被 SWC 转译的 JavaScript 或 TypeScript 文件。

NOTE

在 source.exclude 中配置的文件不会经过 SWC 转译,但被引用的文件仍然会被打包到产物中。

如果你希望某些文件不被打包到产物中,可以使用以下方法:

  • bundle 模式:使用 Rspack 的 IgnorePlugin。
  • bundleless 模式:使用 source.entry 配置相应的 glob 表达式,参考 设置入口。

#source.include source.includesource.include

指定额外需要编译的 JavaScript 文件。

#source.transformImport source.transformImportsource.transformImport

转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 babel-plugin-import。

#source.tsconfigPath source.tsconfigPathsource.tsconfigPath

配置自定义的 tsconfig.json 文件路径,可以是相对路径或绝对路径。

tsconfig.json 配置文件影响 Rslib 的以下行为:

  • paths 字段用于配置 路径别名。
  • experimentalDecorators 字段用于配置 装饰器语法。
  • 用于配置 TypeScript 声明文件生成 时的生效范围、规则以及输出目录。