BannerPlugin

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

const webpack = require(webpack);

new webpack.BannerPlugin(banner);
// 或者
new webpack.BannerPlugin(options);

选项

{
  banner: string | function, // 其值为字符串或函数,将作为注释存在
  raw: boolean, // 如果值为 true,将直接输出,不会被作为注释
  entryOnly: boolean, // 如果值为 true,将只在入口 chunks 文件中添加
  test: string | RegExp | [string, RegExp], // 包含所有匹配的模块
  include: string | RegExp | [string, RegExp], // 根据条件匹配所有模块
  exclude: string | RegExp | [string, RegExp], // 根据条件排除所有模块
  footer?: boolean, // 如果值为 true,banner 将会位于编译结果的最下方
}

用法

import webpack from webpack;

// 字符串
new webpack.BannerPlugin({
  banner: hello world,
});

// 函数
new webpack.BannerPlugin({
  banner: (yourVariable) => {
    return `yourVariable: ${yourVariable}`;
  },
});

占位符

从 webpack 2.5.0 开始,会对 banner 字符串中的占位符取值:

import webpack from webpack;

new webpack.BannerPlugin({
  banner:
    fullhash:[fullhash], chunkhash:[chunkhash], name:[name], filebase:[filebase], query:[query], file:[file],
});

Further Reading

作者:admin,如若转载,请注明出处:https://www.web176.com/webpack/22634.html

(0)
打赏 支付宝 支付宝 微信 微信
adminadmin
上一篇 2023年5月26日
下一篇 2023年5月26日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注