@@ -489,8 +489,11 @@ module.exports = {
489
489
new TerserPlugin ({
490
490
extractComments: {
491
491
condition: / ^ \* * !| @preserve| @license| @cc_on/ i ,
492
- filename : (file ) => {
493
- return ` ${ file} .LICENSE` ;
492
+ filename : (file , fileData ) => {
493
+ // A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
494
+ // You must consider this
495
+ // The "fileData" argument contains object with "filename", "basename", "query"
496
+ return file .replace (/ \. (\w + )($ | \? )/ , ' .$1.LICENSE$2' );
494
497
},
495
498
banner : (licenseFile ) => {
496
499
return ` License information can be found in ${ licenseFile} ` ;
@@ -518,8 +521,10 @@ module.exports = {
518
521
new TerserPlugin ({
519
522
extractComments: {
520
523
condition: ' some' ,
521
- filename : (file ) => {
522
- return ` ${ file} .LICENSE` ;
524
+ filename : (file , fileData ) => {
525
+ // A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
526
+ // You must consider this
527
+ return file .replace (/ \. (\w + )($ | \? )/ , ' .$1.LICENSE$2' );
523
528
},
524
529
banner : (licenseFile ) => {
525
530
return ` License information can be found in ${ licenseFile} ` ;
@@ -534,7 +539,9 @@ module.exports = {
534
539
##### ` filename `
535
540
536
541
Type: ` String|Function<(string) -> String> `
537
- Default: ` ${file}.LICENSE `
542
+ Default: ` [file].LICENSE[query] `
543
+
544
+ Available placeholders: ` [file] ` , ` [query] ` and ` [filebase] ` .
538
545
539
546
The file where the extracted comments will be stored.
540
547
Default is to append the suffix ` .LICENSE ` to the original filename.
@@ -579,8 +586,10 @@ module.exports = {
579
586
new TerserPlugin ({
580
587
extractComments: {
581
588
condition: true ,
582
- filename : (file ) => {
583
- return ` ${ file} .LICENSE` ;
589
+ filename : (file , fileData ) => {
590
+ // A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)
591
+ // You must consider this
592
+ return file .replace (/ \. (\w + )($ | \? )/ , ' .$1.LICENSE$2' );
584
593
},
585
594
banner : (commentsFile ) => {
586
595
return ` My custom banner about license information ${ commentsFile} ` ;
0 commit comments