source

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

source.assetsIncludesource.includesource.include

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

source.decoratorssource.decoratorssource.decorators

用于配置装饰器语法。

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

source.definesource.definesource.define

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

source.entrysource.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.excludesource.excludesource.exclude

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

NOTE

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

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

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

source.includesource.includesource.include

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

source.transformImportsource.transformImportsource.transformImport

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

source.tsconfigPathsource.tsconfigPathsource.tsconfigPath

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