BannerPlugin

new rspack.BannerPlugin(options);

在每个生成的 chunk 顶部或尾部添加一段指定的内容。

  • options

    • 类型:
    type BannerContent = string;
    type BannerRules = string | RegExp | Array<string | RegExp>;
    type BannerPluginOptions = {
      banner: BannerContent;
      entryOnly?: boolean;
      footer?: boolean;
      raw?: boolean;
      test?: BannerRules;
      include?: BannerRules;
      exclude?: BannerRules;
    };
    export type BannerPluginArgument = BannerContent | BannerPluginOptions;
    • 默认值: undefined
    名称类型默认值描述
    bannerstringundefined指定 banner 内容(会被包裹成注释)
    entryOnlyboolean|undefinedundefined如果值为 true,将只在入口 chunks 文件中添加
    footerboolean|undefinedundefined如果值为 true,banner 将会位于编译结果的最下方
    rawboolean|undefinedundefined如果值为 true,将直接输出,不会被作为注释
    testBannerRules|undefinedundefined包含所有匹配的模块
    includeBannerRules|undefinedundefined根据条件匹配指定的模块
    excludeBannerRules|undefinedundefined根据条件排除指定的模块

为每个 chunk 文件头部或底部添加 banner。

rspack.config.js
module.exports = {
  plugins: [
    new rspack.BannerPlugin({
      banner: 'hello world',
      footer: true,
    }),
  ],
};