BannerPlugin 插件
webpackjsorg-main插件参考
BannerPlugin 插件
在每个生成的 chunk 的顶部添加一条横幅。
js
import webpack from "webpack";
new webpack.BannerPlugin(banner);
// or
new webpack.BannerPlugin(options);
选项
ts
{
banner: string | function, // the banner as string or function, it will be wrapped in a comment
raw: boolean, // if true, banner will not be wrapped in a comment
entryOnly: boolean, // if true, the banner will only be added to the entry chunks
test: string | RegExp | [string, RegExp], // Include all modules that pass test assertion.
include: string | RegExp | [string, RegExp], // Include all modules matching any of these conditions.
exclude: string | RegExp | [string, RegExp], // Exclude all modules matching any of these conditions.
footer?: boolean, // if true, the banner will be placed at the end of the compilation
stage?: number, // the stage of the compilation in which the banner should be injected
}
用法
js
import webpack from "webpack";
// string
new webpack.BannerPlugin({
banner: "hello world",
});
// function
new webpack.BannerPlugin({
banner: (yourVariable) => `yourVariable: ${yourVariable}`,
});
// It will add the banner message after minimizers and any asset manipulation
new webpack.BannerPlugin({
raw: true,
banner: "/* banner is a string */",
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,
});
占位符
自 webpack 2.5.0 起,占位符会在 banner 字符串中被求值:
js
import webpack from "webpack";
new webpack.BannerPlugin({
banner:
"fullhash:[fullhash], chunkhash:[chunkhash], name:[name], filebase:[filebase], query:[query], file:[file]",
});
帮助我们改进文档
发现翻译问题或内容错误?请告诉我们。
