close
  • 简体中文
  • source

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

    source.assetsInclude source.assetsIncludesource.assetsInclude

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

    source.decorators source.decoratorssource.decorators

    用于配置装饰器语法。

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

    source.define source.definesource.define

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

    source.entry source.entrysource.entry

    • 命令行: --entry <path>(可重复,例如 --entry index=src/index.ts--entry src/index.ts

      命令行参数支持两种格式:

      1. key=value:显式指定入口名称,例如 --entry main=src/main.ts
      2. value:仅指定路径,此时会自动使用文件的 basename(不含扩展名)作为入口名称。例如 --entry src/index.ts 会生成名为 index 的入口。如果存在同名冲突,则会为所有冲突的入口添加数字后缀(从 0 开始),例如 index0index1

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

    在 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 <path>(例如 --tsconfig tsconfig.build.json

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

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