@@ -470,11 +470,10 @@ function getPlugins(
470470 // I'm going to port "art" to ES modules to avoid this problem.
471471 // Please don't enable this for anything else!
472472 isUMDBundle && entry === 'react-art' && commonjs ( ) ,
473- // License and haste headers, top-level `if` blocks.
474473 {
475- name : 'license-and-headers ' ,
474+ name : 'top-level-definitions ' ,
476475 renderChunk ( source ) {
477- return Wrappers . wrapBundle (
476+ return Wrappers . wrapWithTopLevelDefinitions (
478477 source ,
479478 bundleType ,
480479 globalName ,
@@ -484,6 +483,19 @@ function getPlugins(
484483 ) ;
485484 } ,
486485 } ,
486+ // License and haste headers
487+ {
488+ name : 'license-and-signature-header' ,
489+ renderChunk ( source ) {
490+ return Wrappers . wrapWithLicenseHeader (
491+ source ,
492+ bundleType ,
493+ globalName ,
494+ filename ,
495+ moduleType
496+ ) ;
497+ } ,
498+ } ,
487499 // Apply dead code elimination and/or minification.
488500 // closure doesn't yet support leaving ESM imports intact
489501 needsMinifiedByClosure &&
@@ -527,7 +539,7 @@ function getPlugins(
527539 } ) ,
528540 needsSourcemaps && {
529541 name : 'generate-prod-bundle-sourcemaps' ,
530- async renderChunk ( codeAfterLicense , chunk , options , meta ) {
542+ async renderChunk ( minifiedCodeWithChangedHeader , chunk , options , meta ) {
531543 // We want to generate a sourcemap that shows the production bundle source
532544 // as it existed before Closure Compiler minified that chunk, rather than
533545 // showing the "original" individual source files. This better shows
@@ -583,7 +595,7 @@ function getPlugins(
583595
584596 // Add the sourcemap URL to the actual bundle, so that tools pick it up
585597 const sourceWithMappingUrl =
586- codeAfterLicense +
598+ minifiedCodeWithChangedHeader +
587599 `\n//# sourceMappingURL=${ finalSourcemapFilename } ` ;
588600
589601 return {
@@ -592,6 +604,42 @@ function getPlugins(
592604 } ;
593605 } ,
594606 } ,
607+ // After minification with Closure, the header can be changed.
608+ needsMinifiedByClosure && {
609+ name : 'format-header' ,
610+ renderChunk ( source ) {
611+ // Don't change if its already correct or doesn't start with the header
612+ if ( source . startsWith ( '/**' ) || ! source . startsWith ( '/*' ) ) {
613+ return source ;
614+ }
615+
616+ // Update the header to follow this format:
617+ // /**
618+ // *
619+ // * ...
620+ // */
621+ // We can shift the lines to the right, but don't add / remove lines
622+ // It can break mappings in sourcemaps
623+ const lines = source . split ( / \r \n | \r | \n / ) ;
624+ for ( let lineIndex = 0 ; lineIndex < lines . length ; ++ lineIndex ) {
625+ const currentLine = lines [ lineIndex ] ;
626+
627+ if ( currentLine === '*/' ) {
628+ lines [ lineIndex ] = ' */' ;
629+ break ;
630+ }
631+
632+ if ( currentLine === '/*' ) {
633+ lines [ lineIndex ] = '/**' ;
634+ continue ;
635+ }
636+
637+ lines [ lineIndex ] = ` *${ currentLine } ` ;
638+ }
639+
640+ return lines . join ( '\r\n' ) ;
641+ } ,
642+ } ,
595643 // Record bundle size.
596644 sizes ( {
597645 getSize : ( size , gzip ) => {
0 commit comments