BannerPlugin

new rspack.BannerPlugin(options);

在每个生成的代码块的顶部或底部添加横幅。

选项

  • 类型
type BannerFunction = (args: {
  hash: string;
  chunk: JsChunk;
  filename: string;
}) => string;
type BannerContent = string | BannerFunction;
type BannerPluginOptions = {
  banner: BannerContent;
  entryOnly?: boolean;
  footer?: boolean;
  raw?: boolean;
  stage?: number;
  test?: BannerRules;
  include?: BannerRules;
  exclude?: BannerRules;
};
type BannerPluginArgument = BannerContent | BannerPluginOptions;
  • 默认: undefined
名称类型默认描述
bannerBannerFunction|stringundefined指定横幅,它将被包装在注释中。
entryOnlyboolean|undefinedundefined如果为 true,则横幅将仅添加到入口代码块。
footerboolean|undefinedundefined如果为 true,则横幅将放置在输出的末尾。
rawboolean|undefinedundefined如果为 true,则横幅不会被包装在注释中。
stagenumber|undefinedPROCESS_ASSETS_STAGE_ADDITIONS(-100)编译横幅应该插入的阶段。
testBannerRules|undefinedundefined包含通过测试断言的所有模块。
includeBannerRules|undefinedundefined包含与任何这些条件匹配的所有模块。
excludeBannerRules|undefinedundefined排除与任何这些条件匹配的所有模块。

示例

在每个代码块文件的底部添加横幅。

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