{"size": 632, "ext": "js", "max_stars_repo_path": "webpack_plugins/banner.js", "max_stars_repo_name": "vandvassily/webpack-plugins-loaders", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "webpack_plugins/banner.js", "max_issues_repo_name": "vandvassily/webpack-plugins-loaders", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "webpack_plugins/banner.js", "max_forks_repo_name": "vandvassily/webpack-plugins-loaders", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.28, "max_line_length": 71, "alphanum_fraction": 0.5886075949}
class BannerPlugin {
  constructor(options) {
    this.options = options;
  }
  // compiler 存放了打包的所有内容, webpack实例
  apply(compiler) {
    // emit当把打包的资源放到目标文件的时刻，是个异步钩子
    // complication这次打包的内容
    compiler.hooks.emit.tapAsync("BannerPlugin", (compilation, cb) => {
      const text = `/* ${this.options.banner} */ \n`;
      Object.keys(compilation.assets).forEach((item) => {
        let content = text + compilation.assets[item].source();
        compilation.assets[item] = {
          source: () => content,
          size: () => content.length,
        };
      });

      cb();
    });
  }
}

module.exports = BannerPlugin;
