Skip to content

Commit 7a05452

Browse files
committed
Merge pull request webpack#1052 from larrifax/master
Include/exclude filtering in BannerPlugin
2 parents ac84ef7 + 3ea83f1 commit 7a05452

5 files changed

Lines changed: 47 additions & 6 deletions

File tree

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
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
it("should contain banner in bundle0 chunk", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename, "utf-8");
4+
source.should.containEql("A test value");
5+
});
6+
7+
it("should not contain banner in vendors chunk", function() {
8+
var fs = require("fs"),
9+
path = require("path");
10+
var source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
11+
source.should.not.containEql("A test value");
12+
});
13+
14+
require.include("./test.js");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var foo = {};
2+
3+
module.exports = foo;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var bar = {};
2+
3+
module.exports = bar;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
entry: {
8+
bundle0: ["./index.js"],
9+
vendors: ["./vendors.js"]
10+
},
11+
output: {
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new webpack.BannerPlugin("A test value", {
16+
exclude: ["vendors.js"]
17+
})
18+
]
19+
};

0 commit comments

Comments
 (0)