diff --git a/src/Webpack4Cache.js b/src/Webpack4Cache.js index 5137c312..82c02bac 100644 --- a/src/Webpack4Cache.js +++ b/src/Webpack4Cache.js @@ -55,6 +55,8 @@ export default class Webpack4Cache { input, inputSourceMap, extractedComments, + banner, + shebang, } = cachedResult; if (map) { @@ -70,6 +72,14 @@ export default class Webpack4Cache { cachedResult.source = new RawSource(code); } + if (banner) { + cachedResult.source = new ConcatSource( + shebang ? `${shebang}\n` : '', + `/*! ${banner} */\n`, + cachedResult.source + ); + } + if (extractedComments) { cachedResult.extractedCommentsSource = new RawSource(extractedComments); } @@ -105,6 +115,8 @@ export default class Webpack4Cache { map: cacheData.map, input: cacheData.input, inputSourceMap: cacheData.inputSourceMap, + banner: cacheData.banner, + shebang: cacheData.shebang, }; if (cacheData.extractedCommentsSource) { diff --git a/src/index.js b/src/index.js index 5322b15a..e1772557 100644 --- a/src/index.js +++ b/src/index.js @@ -323,6 +323,7 @@ class TerserPlugin { let output = await cache.get(cacheData, { RawSource, + ConcatSource, SourceMapSource, }); @@ -433,6 +434,8 @@ class TerserPlugin { `/*! ${banner} */\n`, output.source ); + output.banner = banner; + output.shebang = shebang; } } diff --git a/test/__snapshots__/cache-option.test.js.snap.webpack4 b/test/__snapshots__/cache-option.test.js.snap.webpack4 index e429e7ea..8e18bf08 100644 --- a/test/__snapshots__/cache-option.test.js.snap.webpack4 +++ b/test/__snapshots__/cache-option.test.js.snap.webpack4 @@ -129,18 +129,21 @@ Object { exports[`"cache" option should match snapshot for the "true" value and extract comments in different files: assets 2`] = ` Object { - "4.4.js": "(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{4:function(n,o){n.exports=Math.random()}}]);", + "4.4.js": "/*! For license information please see 4.4.js.LICENSE.txt */ +(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{4:function(n,o){n.exports=Math.random()}}]);", "4.4.js.LICENSE.txt": "/*! Legal Comment */ /** @license Copyright 2112 Moon. **/ ", - "four.js": "!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,\\"a\\",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p=\\"\\",r(r.s=3)}({3:function(e,t){e.exports=Math.random()}});", + "four.js": "/*! For license information please see four.js.LICENSE.txt */ +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,\\"a\\",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p=\\"\\",r(r.s=3)}({3:function(e,t){e.exports=Math.random()}});", "four.js.LICENSE.txt": "/** * Duplicate comment in difference files. * @license MIT */ ", - "one.js": "!function(e){function t(t){for(var r,o,u=t[0],i=t[1],a=0,l=[];a