Skip to content

Commit 9627518

Browse files
committed
added BannerPlugin
1 parent 72f29bf commit 9627518

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/BannerPlugin.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
var ConcatSource = require("webpack-core/lib/ConcatSource");
6+
7+
function wrapComment(str) {
8+
if(str.indexOf("\n") < 0) return "/*! " + str + " */";
9+
return "/*!\n * " + str.split("\n").join("\n * ") + "\n */";
10+
}
11+
12+
function BannerPlugin(banner, options) {
13+
if(!options) options = {};
14+
this.banner = options.raw ? banner : wrapComment(banner);
15+
this.entryOnly = options.entryOnly;
16+
}
17+
module.exports = BannerPlugin;
18+
BannerPlugin.prototype.apply = function(compiler) {
19+
var banner = this.banner;
20+
var entryOnly = this.entryOnly;
21+
compiler.plugin("compilation", function(compilation) {
22+
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
23+
chunks.forEach(function(chunk) {
24+
if(entryOnly && !chunk.entry) return;
25+
chunk.files.forEach(function(file) {
26+
compilation.assets[file] = new ConcatSource(banner, "\n", compilation.assets[file]);
27+
});
28+
});
29+
callback();
30+
});
31+
});
32+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.10.0-beta9",
3+
"version": "0.10.0-beta10",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {

0 commit comments

Comments
 (0)