@@ -13,49 +13,6 @@ const wrapComment = (str) => {
1313 return `/*!\n * ${ str . split ( "\n" ) . join ( "\n * " ) } \n */` ;
1414} ;
1515
16- const REGEXP_HASH = / \[ h a s h : ? ( \d + ) ? \] / gi,
17- REGEXP_CHUNKHASH = / \[ c h u n k h a s h : ? ( \d + ) ? \] / gi,
18- REGEXP_NAME = / \[ n a m e \] / gi,
19- REGEXP_EXT = / \[ e x t \] / gi;
20-
21- // withHashLength, getReplacer from lib/TemplatedPathPlugin.js
22- const withHashLength = ( replacer , handlerFn ) => {
23- return function ( _ , hashLength ) {
24- const length = hashLength && parseInt ( hashLength , 10 ) ;
25- if ( length && handlerFn ) {
26- return handlerFn ( length ) ;
27- }
28-
29- const hash = replacer . apply ( this , arguments ) ;
30- return length ? hash . slice ( 0 , length ) : hash ;
31- } ;
32- } ;
33-
34- const getReplacer = ( value ) => {
35- return function ( match ) {
36- return `${ value } ` ;
37- } ;
38- } ;
39-
40- const interpolate = ( banner , file , hash , chunkHash ) => {
41- let name , ext ;
42- const splitPoint = file . lastIndexOf ( "." ) ;
43-
44- if ( splitPoint > - 1 ) {
45- name = file . slice ( 0 , splitPoint ) ;
46- ext = file . slice ( splitPoint , - 1 ) ;
47- } else {
48- name = file ;
49- ext = "" ;
50- }
51-
52- return banner
53- . replace ( REGEXP_HASH , withHashLength ( getReplacer ( hash ) ) )
54- . replace ( REGEXP_CHUNKHASH , withHashLength ( getReplacer ( chunkHash ) ) )
55- . replace ( REGEXP_NAME , name )
56- . replace ( REGEXP_EXT , ext ) ;
57- } ;
58-
5916class BannerPlugin {
6017 constructor ( options ) {
6118 if ( arguments . length > 1 )
@@ -79,8 +36,24 @@ class BannerPlugin {
7936 chunk . files
8037 . filter ( ModuleFilenameHelpers . matchObject . bind ( undefined , options ) )
8138 . forEach ( ( file ) => {
82- const chunkHash = chunk . renderedHash || chunk . hash ;
83- const comment = interpolate ( banner , file , compilation . hash , chunkHash ) ;
39+ let filename , basename ;
40+ const splitPoint = file . lastIndexOf ( "." ) ;
41+
42+ if ( splitPoint > 0 ) {
43+ filename = file . slice ( 0 , splitPoint ) ;
44+ basename = file . slice ( splitPoint , - 1 ) ;
45+ } else {
46+ filename = file ;
47+ basename = "" ;
48+ }
49+
50+ const comment = compilation . getPath ( banner , {
51+ hash : compilation . hash ,
52+ chunk,
53+ filename,
54+ basename,
55+ } ) ;
56+
8457 return compilation . assets [ file ] = new ConcatSource ( comment , "\n" , compilation . assets [ file ] ) ;
8558 } ) ;
8659 } ) ;
0 commit comments