moved banner plugin placeholdertesting to separate dir

This commit is contained in:
Travis Matthews 2017-04-05 21:08:21 -04:00
parent e1a20425e9
commit e5575594d8
10 changed files with 21 additions and 78 deletions

View File

@ -13,6 +13,22 @@ function wrapComment(str) {
return `/*!\n * ${str.split("\n").join("\n * ")}\n */`;
}
/*The following tokens are replaced in the name parameter:
*
*[ext] the extension of the resource
*[name] the basename of the resource
*[path] the path of the resource relative to the context query parameter or option.
*[folder] the folder of the resource is in.
*[emoji] a random emoji representation of options.content
*[emoji:<length>] same as above, but with a customizable number of emojis
*[hash] the hash of options.content (Buffer) (by default it's the hex digest of the md5 hash)
*[<hashType>:hash:<digestType>:<length>] optionally one can configure
*other hashTypes, i. e. sha1, md5, sha256, sha512
*other digestTypes, i. e. hex, base26, base32, base36, base49, base52, base58, base62, base64
*and length the length in chars
*[N] the N-th match obtained from matching the current file name against options.regExp
*/
class BannerPlugin {
constructor(options) {
if(arguments.length > 1)
@ -30,17 +46,18 @@ class BannerPlugin {
const banner = this.banner;
compiler.plugin("compilation", (compilation) => {
console.log('compilation: ', compilation);
compilation.plugin("optimize-chunk-assets", (chunks, callback) => {
chunks.forEach((chunk) => {
if(options.entryOnly && !chunk.isInitial()) return;
chunk.files
.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options))
.forEach((file) =>
compilation.assets[file] = new ConcatSource(
.forEach((file) => {
return compilation.assets[file] = new ConcatSource(
banner, "\n", compilation.assets[file]
)
);
});
});
callback();
});

View File

@ -1,8 +0,0 @@
it("should interpolate filename hash into banner", function() {
var fs = require("fs"),
path = require("path");
var source = fs.readFileSync(__filename, "utf-8");
source.should.not.containEql("hash");
});
require.include("./test.js");

View File

@ -1,3 +0,0 @@
var foo = {};
module.exports = foo;

View File

@ -1,3 +0,0 @@
var bar = {};
module.exports = bar;

View File

@ -1,20 +0,0 @@
var webpack = require("../../../../");
module.exports = {
node: {
__dirname: false,
__filename: false
},
entry: {
bundle0: ["./index.js"],
vendors: ["./vendors.js"]
},
output: {
filename: "[name].js"
},
plugins: [
new webpack.BannerPlugin({
banner: "[hash]",
exclude: ["vendors.js"]
})
]
};

View File

@ -1,14 +0,0 @@
it("should contain banner in bundle0 chunk", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
source.should.containEql("A test value");
});
it("should not contain banner in vendors chunk", function() {
var fs = require("fs"),
path = require("path");
var source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8");
source.should.not.containEql("A test value");
});
require.include("./test.js");

View File

@ -1,3 +0,0 @@
var foo = {};
module.exports = foo;

View File

@ -1,3 +0,0 @@
var bar = {};
module.exports = bar;

View File

@ -1,20 +0,0 @@
var webpack = require("../../../../");
module.exports = {
node: {
__dirname: false,
__filename: false
},
entry: {
bundle0: ["./index.js"],
vendors: ["./vendors.js"]
},
output: {
filename: "[name].js"
},
plugins: [
new webpack.BannerPlugin({
banner: "A test value",
exclude: ["vendors.js"]
})
]
};

View File

@ -13,7 +13,7 @@ module.exports = {
},
plugins: [
new webpack.BannerPlugin({
banner: "A test value",
banner: "[hash]",
exclude: ["vendors.js"]
})
]