mirror of https://github.com/webpack/webpack.git
moved banner plugin placeholdertesting to separate dir
This commit is contained in:
parent
e1a20425e9
commit
e5575594d8
|
|
@ -13,6 +13,22 @@ function wrapComment(str) {
|
||||||
return `/*!\n * ${str.split("\n").join("\n * ")}\n */`;
|
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 {
|
class BannerPlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if(arguments.length > 1)
|
if(arguments.length > 1)
|
||||||
|
|
@ -30,17 +46,18 @@ class BannerPlugin {
|
||||||
const banner = this.banner;
|
const banner = this.banner;
|
||||||
|
|
||||||
compiler.plugin("compilation", (compilation) => {
|
compiler.plugin("compilation", (compilation) => {
|
||||||
|
console.log('compilation: ', compilation);
|
||||||
compilation.plugin("optimize-chunk-assets", (chunks, callback) => {
|
compilation.plugin("optimize-chunk-assets", (chunks, callback) => {
|
||||||
chunks.forEach((chunk) => {
|
chunks.forEach((chunk) => {
|
||||||
if(options.entryOnly && !chunk.isInitial()) return;
|
if(options.entryOnly && !chunk.isInitial()) return;
|
||||||
|
|
||||||
chunk.files
|
chunk.files
|
||||||
.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options))
|
.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options))
|
||||||
.forEach((file) =>
|
.forEach((file) => {
|
||||||
compilation.assets[file] = new ConcatSource(
|
return compilation.assets[file] = new ConcatSource(
|
||||||
banner, "\n", compilation.assets[file]
|
banner, "\n", compilation.assets[file]
|
||||||
)
|
)
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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");
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
var foo = {};
|
|
||||||
|
|
||||||
module.exports = foo;
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
var bar = {};
|
|
||||||
|
|
||||||
module.exports = bar;
|
|
||||||
|
|
@ -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"]
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
@ -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");
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
var foo = {};
|
|
||||||
|
|
||||||
module.exports = foo;
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
var bar = {};
|
|
||||||
|
|
||||||
module.exports = bar;
|
|
||||||
|
|
@ -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"]
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.BannerPlugin({
|
new webpack.BannerPlugin({
|
||||||
banner: "A test value",
|
banner: "[hash]",
|
||||||
exclude: ["vendors.js"]
|
exclude: ["vendors.js"]
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue