BannerPlugin

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

  1. const webpack = require('webpack');
  2. new webpack.BannerPlugin(banner);
  3. // or
  4. new webpack.BannerPlugin(options);

选项

  1. {
  2. banner: string | function, // 其值为字符串或函数,将作为注释存在
  3. raw: boolean, // 如果值为 true,将直出,不会被作为注释
  4. entryOnly: boolean, // 如果值为 true,将只在入口 chunks 文件中添加
  5. test: string | RegExp | Array,
  6. include: string | RegExp | Array,
  7. exclude: string | RegExp | Array,
  8. }

Usage

  1. import webpack from 'webpack';
  2. // string
  3. new webpack.BannerPlugin({
  4. banner: 'hello world'
  5. });
  6. // function
  7. new webpack.BannerPlugin({
  8. banner: (yourVariable) => { return `yourVariable: ${yourVariable}`; }
  9. });

占位符(placeholder)

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

  1. import webpack from 'webpack';
  2. new webpack.BannerPlugin({
  3. banner: 'hash:[hash], chunkhash:[chunkhash], name:[name], filebase:[filebase], query:[query], file:[file]'
  4. });

进一步阅读


贡献人员

byzyk byzyk simon04 simon04