Skip to content

Commit b76aa12

Browse files
committed
Add include/exclude filtering to BannerPlugin
1 parent 0d7aba1 commit b76aa12

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/BannerPlugin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33
Author Tobias Koppers @sokra
44
*/
55
var ConcatSource = require("webpack-core/lib/ConcatSource");
6+
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
67

78
function wrapComment(str) {
89
if(str.indexOf("\n") < 0) return "/*! " + str + " */";
910
return "/*!\n * " + str.split("\n").join("\n * ") + "\n */";
1011
}
1112

1213
function BannerPlugin(banner, options) {
13-
if(!options) options = {};
14-
this.banner = options.raw ? banner : wrapComment(banner);
15-
this.entryOnly = options.entryOnly;
14+
this.options = options || {};
15+
this.banner = this.options.raw ? banner : wrapComment(banner);
1616
}
1717
module.exports = BannerPlugin;
18+
1819
BannerPlugin.prototype.apply = function(compiler) {
20+
var options = this.options;
1921
var banner = this.banner;
20-
var entryOnly = this.entryOnly;
22+
2123
compiler.plugin("compilation", function(compilation) {
2224
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
2325
chunks.forEach(function(chunk) {
24-
if(entryOnly && !chunk.initial) return;
25-
chunk.files.forEach(function(file) {
26+
if(options.entryOnly && !chunk.initial) return;
27+
chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).forEach(function(file) {
2628
compilation.assets[file] = new ConcatSource(banner, "\n", compilation.assets[file]);
2729
});
2830
});

0 commit comments

Comments
 (0)