mirror of https://github.com/webpack/webpack.git
Allow banner to be placed as a footer
This commit is contained in:
parent
c2079f7e76
commit
4f2adf9d02
|
@ -38,6 +38,10 @@ export interface BannerPluginOptions {
|
||||||
* Exclude all modules matching any of these conditions.
|
* Exclude all modules matching any of these conditions.
|
||||||
*/
|
*/
|
||||||
exclude?: Rules;
|
exclude?: Rules;
|
||||||
|
/**
|
||||||
|
* If true, banner will be placed at the end of the output.
|
||||||
|
*/
|
||||||
|
footer?: boolean;
|
||||||
/**
|
/**
|
||||||
* Include all modules matching any of these conditions.
|
* Include all modules matching any of these conditions.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -106,7 +106,9 @@ class BannerPlugin {
|
||||||
compilation.updateAsset(file, old => {
|
compilation.updateAsset(file, old => {
|
||||||
let cached = cache.get(old);
|
let cached = cache.get(old);
|
||||||
if (!cached || cached.comment !== comment) {
|
if (!cached || cached.comment !== comment) {
|
||||||
const source = new ConcatSource(comment, "\n", old);
|
const source = options.footer
|
||||||
|
? new ConcatSource(old, "\n", comment)
|
||||||
|
: new ConcatSource(comment, "\n", old);
|
||||||
cache.set(old, { source, comment });
|
cache.set(old, { source, comment });
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
* DO NOT MODIFY BY HAND.
|
* DO NOT MODIFY BY HAND.
|
||||||
* Run `yarn special-lint-fix` to update
|
* Run `yarn special-lint-fix` to update
|
||||||
*/
|
*/
|
||||||
"use strict";function n(t,{instancePath:l="",parentData:s,parentDataProperty:e,rootData:a=t}={}){let r=null,o=0;const u=o;let i=!1;const p=o;if(o===p)if(Array.isArray(t)){const n=t.length;for(let l=0;l<n;l++){let n=t[l];const s=o,e=o;let a=!1,u=null;const i=o,p=o;let f=!1;const h=o;if(!(n instanceof RegExp)){const n={params:{}};null===r?r=[n]:r.push(n),o++}var c=h===o;if(f=f||c,!f){const t=o;if(o===t)if("string"==typeof n){if(n.length<1){const n={params:{}};null===r?r=[n]:r.push(n),o++}}else{const n={params:{type:"string"}};null===r?r=[n]:r.push(n),o++}c=t===o,f=f||c}if(f)o=p,null!==r&&(p?r.length=p:r=null);else{const n={params:{}};null===r?r=[n]:r.push(n),o++}if(i===o&&(a=!0,u=0),a)o=e,null!==r&&(e?r.length=e:r=null);else{const n={params:{passingSchemas:u}};null===r?r=[n]:r.push(n),o++}if(s!==o)break}}else{const n={params:{type:"array"}};null===r?r=[n]:r.push(n),o++}var f=p===o;if(i=i||f,!i){const n=o,l=o;let s=!1;const e=o;if(!(t instanceof RegExp)){const n={params:{}};null===r?r=[n]:r.push(n),o++}var h=e===o;if(s=s||h,!s){const n=o;if(o===n)if("string"==typeof t){if(t.length<1){const n={params:{}};null===r?r=[n]:r.push(n),o++}}else{const n={params:{type:"string"}};null===r?r=[n]:r.push(n),o++}h=n===o,s=s||h}if(s)o=l,null!==r&&(l?r.length=l:r=null);else{const n={params:{}};null===r?r=[n]:r.push(n),o++}f=n===o,i=i||f}if(!i){const t={params:{}};return null===r?r=[t]:r.push(t),o++,n.errors=r,!1}return o=u,null!==r&&(u?r.length=u:r=null),n.errors=r,0===o}function t(l,{instancePath:s="",parentData:e,parentDataProperty:a,rootData:r=l}={}){let o=null,u=0;const i=u;let p=!1;const c=u;if(u===c)if("string"==typeof l){if(l.length<1){const n={params:{}};null===o?o=[n]:o.push(n),u++}}else{const n={params:{type:"string"}};null===o?o=[n]:o.push(n),u++}var f=c===u;if(p=p||f,!p){const t=u;if(u===t)if(l&&"object"==typeof l&&!Array.isArray(l)){let t;if(void 0===l.banner&&(t="banner")){const n={params:{missingProperty:t}};null===o?o=[n]:o.push(n),u++}else{const t=u;for(const n in l)if("banner"!==n&&"entryOnly"!==n&&"exclude"!==n&&"include"!==n&&"raw"!==n&&"test"!==n){const t={params:{additionalProperty:n}};null===o?o=[t]:o.push(t),u++;break}if(t===u){if(void 0!==l.banner){let n=l.banner;const t=u,s=u;let e=!1;const a=u;if("string"!=typeof n){const n={params:{type:"string"}};null===o?o=[n]:o.push(n),u++}var h=a===u;if(e=e||h,!e){const t=u;if(!(n instanceof Function)){const n={params:{}};null===o?o=[n]:o.push(n),u++}h=t===u,e=e||h}if(e)u=s,null!==o&&(s?o.length=s:o=null);else{const n={params:{}};null===o?o=[n]:o.push(n),u++}var m=t===u}else m=!0;if(m){if(void 0!==l.entryOnly){const n=u;if("boolean"!=typeof l.entryOnly){const n={params:{type:"boolean"}};null===o?o=[n]:o.push(n),u++}m=n===u}else m=!0;if(m){if(void 0!==l.exclude){const t=u,e=u;let a=!1,i=null;const p=u;if(n(l.exclude,{instancePath:s+"/exclude",parentData:l,parentDataProperty:"exclude",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=e,null!==o&&(e?o.length=e:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}m=t===u}else m=!0;if(m){if(void 0!==l.include){const t=u,e=u;let a=!1,i=null;const p=u;if(n(l.include,{instancePath:s+"/include",parentData:l,parentDataProperty:"include",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=e,null!==o&&(e?o.length=e:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}m=t===u}else m=!0;if(m){if(void 0!==l.raw){const n=u;if("boolean"!=typeof l.raw){const n={params:{type:"boolean"}};null===o?o=[n]:o.push(n),u++}m=n===u}else m=!0;if(m)if(void 0!==l.test){const t=u,e=u;let a=!1,i=null;const p=u;if(n(l.test,{instancePath:s+"/test",parentData:l,parentDataProperty:"test",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=e,null!==o&&(e?o.length=e:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}m=t===u}else m=!0}}}}}}}else{const n={params:{type:"object"}};null===o?o=[n]:o.push(n),u++}if(f=t===u,p=p||f,!p){const n=u;if(!(l instanceof Function)){const n={params:{}};null===o?o=[n]:o.push(n),u++}f=n===u,p=p||f}}if(!p){const n={params:{}};return null===o?o=[n]:o.push(n),u++,t.errors=o,!1}return u=i,null!==o&&(i?o.length=i:o=null),t.errors=o,0===u}module.exports=t,module.exports.default=t;
|
"use strict";function n(t,{instancePath:l="",parentData:e,parentDataProperty:s,rootData:a=t}={}){let r=null,o=0;const u=o;let i=!1;const p=o;if(o===p)if(Array.isArray(t)){const n=t.length;for(let l=0;l<n;l++){let n=t[l];const e=o,s=o;let a=!1,u=null;const i=o,p=o;let f=!1;const h=o;if(!(n instanceof RegExp)){const n={params:{}};null===r?r=[n]:r.push(n),o++}var c=h===o;if(f=f||c,!f){const t=o;if(o===t)if("string"==typeof n){if(n.length<1){const n={params:{}};null===r?r=[n]:r.push(n),o++}}else{const n={params:{type:"string"}};null===r?r=[n]:r.push(n),o++}c=t===o,f=f||c}if(f)o=p,null!==r&&(p?r.length=p:r=null);else{const n={params:{}};null===r?r=[n]:r.push(n),o++}if(i===o&&(a=!0,u=0),a)o=s,null!==r&&(s?r.length=s:r=null);else{const n={params:{passingSchemas:u}};null===r?r=[n]:r.push(n),o++}if(e!==o)break}}else{const n={params:{type:"array"}};null===r?r=[n]:r.push(n),o++}var f=p===o;if(i=i||f,!i){const n=o,l=o;let e=!1;const s=o;if(!(t instanceof RegExp)){const n={params:{}};null===r?r=[n]:r.push(n),o++}var h=s===o;if(e=e||h,!e){const n=o;if(o===n)if("string"==typeof t){if(t.length<1){const n={params:{}};null===r?r=[n]:r.push(n),o++}}else{const n={params:{type:"string"}};null===r?r=[n]:r.push(n),o++}h=n===o,e=e||h}if(e)o=l,null!==r&&(l?r.length=l:r=null);else{const n={params:{}};null===r?r=[n]:r.push(n),o++}f=n===o,i=i||f}if(!i){const t={params:{}};return null===r?r=[t]:r.push(t),o++,n.errors=r,!1}return o=u,null!==r&&(u?r.length=u:r=null),n.errors=r,0===o}function t(l,{instancePath:e="",parentData:s,parentDataProperty:a,rootData:r=l}={}){let o=null,u=0;const i=u;let p=!1;const c=u;if(u===c)if("string"==typeof l){if(l.length<1){const n={params:{}};null===o?o=[n]:o.push(n),u++}}else{const n={params:{type:"string"}};null===o?o=[n]:o.push(n),u++}var f=c===u;if(p=p||f,!p){const t=u;if(u===t)if(l&&"object"==typeof l&&!Array.isArray(l)){let t;if(void 0===l.banner&&(t="banner")){const n={params:{missingProperty:t}};null===o?o=[n]:o.push(n),u++}else{const t=u;for(const n in l)if("banner"!==n&&"entryOnly"!==n&&"exclude"!==n&&"footer"!==n&&"include"!==n&&"raw"!==n&&"test"!==n){const t={params:{additionalProperty:n}};null===o?o=[t]:o.push(t),u++;break}if(t===u){if(void 0!==l.banner){let n=l.banner;const t=u,e=u;let s=!1;const a=u;if("string"!=typeof n){const n={params:{type:"string"}};null===o?o=[n]:o.push(n),u++}var h=a===u;if(s=s||h,!s){const t=u;if(!(n instanceof Function)){const n={params:{}};null===o?o=[n]:o.push(n),u++}h=t===u,s=s||h}if(s)u=e,null!==o&&(e?o.length=e:o=null);else{const n={params:{}};null===o?o=[n]:o.push(n),u++}var y=t===u}else y=!0;if(y){if(void 0!==l.entryOnly){const n=u;if("boolean"!=typeof l.entryOnly){const n={params:{type:"boolean"}};null===o?o=[n]:o.push(n),u++}y=n===u}else y=!0;if(y){if(void 0!==l.exclude){const t=u,s=u;let a=!1,i=null;const p=u;if(n(l.exclude,{instancePath:e+"/exclude",parentData:l,parentDataProperty:"exclude",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=s,null!==o&&(s?o.length=s:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}y=t===u}else y=!0;if(y){if(void 0!==l.footer){const n=u;if("boolean"!=typeof l.footer){const n={params:{type:"boolean"}};null===o?o=[n]:o.push(n),u++}y=n===u}else y=!0;if(y){if(void 0!==l.include){const t=u,s=u;let a=!1,i=null;const p=u;if(n(l.include,{instancePath:e+"/include",parentData:l,parentDataProperty:"include",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=s,null!==o&&(s?o.length=s:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}y=t===u}else y=!0;if(y){if(void 0!==l.raw){const n=u;if("boolean"!=typeof l.raw){const n={params:{type:"boolean"}};null===o?o=[n]:o.push(n),u++}y=n===u}else y=!0;if(y)if(void 0!==l.test){const t=u,s=u;let a=!1,i=null;const p=u;if(n(l.test,{instancePath:e+"/test",parentData:l,parentDataProperty:"test",rootData:r})||(o=null===o?n.errors:o.concat(n.errors),u=o.length),p===u&&(a=!0,i=0),a)u=s,null!==o&&(s?o.length=s:o=null);else{const n={params:{passingSchemas:i}};null===o?o=[n]:o.push(n),u++}y=t===u}else y=!0}}}}}}}}else{const n={params:{type:"object"}};null===o?o=[n]:o.push(n),u++}if(f=t===u,p=p||f,!p){const n=u;if(!(l instanceof Function)){const n={params:{}};null===o?o=[n]:o.push(n),u++}f=n===u,p=p||f}}if(!p){const n={params:{}};return null===o?o=[n]:o.push(n),u++,t.errors=o,!1}return u=i,null!==o&&(i?o.length=i:o=null),t.errors=o,0===u}module.exports=t,module.exports.default=t;
|
|
@ -73,6 +73,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"footer": {
|
||||||
|
"description": "If true, banner will be placed at the end of the output.",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"include": {
|
"include": {
|
||||||
"description": "Include all modules matching any of these conditions.",
|
"description": "Include all modules matching any of these conditions.",
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
|
|
|
@ -5,11 +5,15 @@ const fs = require("graceful-fs");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
|
|
||||||
|
const pluginDir = path.join(__dirname, "js", "BannerPlugin");
|
||||||
|
const outputDir = path.join(pluginDir, "output");
|
||||||
|
|
||||||
it("should cache assets", done => {
|
it("should cache assets", done => {
|
||||||
const entry1File = path.join(__dirname, "js", "BannerPlugin", "entry1.js");
|
const entry1File = path.join(pluginDir, "entry1.js");
|
||||||
const entry2File = path.join(__dirname, "js", "BannerPlugin", "entry2.js");
|
const entry2File = path.join(pluginDir, "entry2.js");
|
||||||
|
const outputFile = path.join(outputDir, "entry1.js");
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(path.join(__dirname, "js", "BannerPlugin"), {
|
fs.mkdirSync(path.join(pluginDir), {
|
||||||
recursive: true
|
recursive: true
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -22,7 +26,7 @@ it("should cache assets", done => {
|
||||||
entry2: entry2File
|
entry2: entry2File
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, "js", "BannerPlugin", "output")
|
path: outputDir
|
||||||
},
|
},
|
||||||
plugins: [new webpack.BannerPlugin("banner is a string")]
|
plugins: [new webpack.BannerPlugin("banner is a string")]
|
||||||
});
|
});
|
||||||
|
@ -30,6 +34,8 @@ it("should cache assets", done => {
|
||||||
fs.writeFileSync(entry2File, "1", "utf-8");
|
fs.writeFileSync(entry2File, "1", "utf-8");
|
||||||
compiler.run(err => {
|
compiler.run(err => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
const footerFileResults = fs.readFileSync(outputFile, "utf8").split("\n");
|
||||||
|
expect(footerFileResults[0]).toBe("/*! banner is a string */");
|
||||||
fs.writeFileSync(entry2File, "2", "utf-8");
|
fs.writeFileSync(entry2File, "2", "utf-8");
|
||||||
compiler.run((err, stats) => {
|
compiler.run((err, stats) => {
|
||||||
const { assets } = stats.toJson();
|
const { assets } = stats.toJson();
|
||||||
|
@ -39,3 +45,37 @@ it("should cache assets", done => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can place banner as footer", done => {
|
||||||
|
const footerFile = path.join(pluginDir, "footerFile.js");
|
||||||
|
const outputFile = path.join(outputDir, "footerFile.js");
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.join(pluginDir), {
|
||||||
|
recursive: true
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
const compiler = webpack({
|
||||||
|
mode: "development",
|
||||||
|
entry: {
|
||||||
|
footerFile: footerFile
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: outputDir
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.BannerPlugin({
|
||||||
|
banner: "banner is a string",
|
||||||
|
footer: true
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
fs.writeFileSync(footerFile, "footer", "utf-8");
|
||||||
|
compiler.run(err => {
|
||||||
|
if (err) return done(err);
|
||||||
|
const footerFileResults = fs.readFileSync(outputFile, "utf8").split("\n");
|
||||||
|
expect(footerFileResults.pop()).toBe("/*! banner is a string */");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -430,6 +430,11 @@ declare interface BannerPluginOptions {
|
||||||
*/
|
*/
|
||||||
exclude?: string | RegExp | Rule[];
|
exclude?: string | RegExp | Rule[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, banner will be placed at the end of the output.
|
||||||
|
*/
|
||||||
|
footer?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include all modules matching any of these conditions.
|
* Include all modules matching any of these conditions.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue