|
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | 5 | var ConcatSource = require("webpack-core/lib/ConcatSource"); |
| 6 | +var ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); |
6 | 7 |
|
7 | 8 | function wrapComment(str) { |
8 | 9 | if(str.indexOf("\n") < 0) return "/*! " + str + " */"; |
9 | 10 | return "/*!\n * " + str.split("\n").join("\n * ") + "\n */"; |
10 | 11 | } |
11 | 12 |
|
12 | 13 | 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); |
16 | 16 | } |
17 | 17 | module.exports = BannerPlugin; |
| 18 | + |
18 | 19 | BannerPlugin.prototype.apply = function(compiler) { |
| 20 | + var options = this.options; |
19 | 21 | var banner = this.banner; |
20 | | - var entryOnly = this.entryOnly; |
| 22 | + |
21 | 23 | compiler.plugin("compilation", function(compilation) { |
22 | 24 | compilation.plugin("optimize-chunk-assets", function(chunks, callback) { |
23 | 25 | 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) { |
26 | 28 | compilation.assets[file] = new ConcatSource(banner, "\n", compilation.assets[file]); |
27 | 29 | }); |
28 | 30 | }); |
|
0 commit comments