source
与输入的源代码相关的选项。
source.assetsInclude
source.include
指定需要被视为静态资源的额外文件类型。
source.decorators
source.decorators
用于配置装饰器语法。
如果在 tsconfig.json 中启用了 experimentalDecorators,Rslib 会默认将 source.decorators.version 设置为 legacy。
source.define
source.define
构建时将代码中的变量替换成其它值或者表达式,可以用于在构建时向代码注入环境变量等信息。
source.entry
source.entry
-
命令行:
--entry <path>(可重复,例如--entry index=src/index.ts或--entry src/index.ts)命令行参数支持两种格式:
key=value:显式指定入口名称,例如--entry main=src/main.ts。value:仅指定路径,此时会自动使用文件的 basename(不含扩展名)作为入口名称。例如--entry src/index.ts会生成名为index的入口。如果存在同名冲突,则会为所有冲突的入口添加数字后缀(从 0 开始),例如index0、index1。
用于设置构建的入口模块。
在 Rslib 中,默认值为:
- bundle 模式:
- bundleless 模式:
Info
参考 lib.bundle 进一步了解如何为 bundle 和 bundleless 项目设置入口。
source.exclude
source.exclude
排除不需要被 SWC 转译的 JavaScript 或 TypeScript 文件。
Note
在 source.exclude 中配置的文件不会经过 SWC 转译,但被引用的文件仍然会被打包到产物中。
如果你希望某些文件不被打包到产物中,可以使用以下方法:
- bundle 模式:使用 Rspack 的 IgnorePlugin。
- bundleless 模式:使用
source.entry配置相应的 glob 表达式,参考 设置入口。
source.include
source.include
指定额外需要编译的 JavaScript 文件。
source.transformImport
source.transformImport
转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 babel-plugin-import。
source.tsconfigPath
source.tsconfigPath
- 命令行:
--tsconfig <path>(例如--tsconfig tsconfig.build.json)
配置自定义的 tsconfig.json 文件路径,可以是相对路径或绝对路径。
tsconfig.json 配置文件影响 Rslib 的以下行为:
paths字段用于配置 路径别名。experimentalDecorators字段用于配置 装饰器语法。- 用于配置 TypeScript 声明文件生成 时的生效范围、规则以及输出目录。
