@@ -386,6 +386,7 @@ function createConfig(options, entry, format, writeMeta) {
386386 }
387387
388388 const modern = format === 'modern' || format === 'debug' ;
389+ const shouldCompress = options . compress !== false && format !== 'debug' ;
389390
390391 // let rollupName = safeVariableName(basename(entry).replace(/\.js$/, ''));
391392
@@ -504,7 +505,7 @@ function createConfig(options, entry, format, writeMeta) {
504505 ! ! writeMeta &&
505506 options . css !== 'inline' &&
506507 absMain . replace ( EXTENSION , '.css' ) ,
507- minimize : options . compress ,
508+ minimize : shouldCompress ,
508509 sourceMap : options . sourcemap && options . css !== 'inline' ,
509510 } ) ,
510511 moduleAliases . length > 0 &&
@@ -593,63 +594,62 @@ function createConfig(options, entry, format, writeMeta) {
593594 custom : {
594595 defines,
595596 modern,
596- compress : options . compress !== false && format !== 'debug' ,
597+ compress : shouldCompress ,
597598 targets : options . target === 'node' ? { node : '12' } : undefined ,
598599 pragma : options . jsx ,
599600 pragmaFrag : options . jsxFragment ,
600601 typescript : ! ! useTypescript ,
601602 jsxImportSource : options . jsxImportSource || false ,
602603 } ,
603604 } ) ,
604- options . compress !== false &&
605- format !== 'debug' && [
606- terser ( {
607- compress : Object . assign (
608- {
609- keep_infinity : true ,
610- pure_getters : true ,
611- // Ideally we'd just get Terser to respect existing Arrow functions...
612- // unsafe_arrows: true,
613- passes : 10 ,
614- } ,
615- typeof minifyOptions . compress === 'boolean'
616- ? minifyOptions . compress
617- : minifyOptions . compress || { } ,
618- ) ,
619- format : {
620- // By default, Terser wraps function arguments in extra parens to trigger eager parsing.
621- // Whether this is a good idea is way too specific to guess, so we optimize for size by default:
622- wrap_func_args : false ,
623- comments : / ^ \s * ( [ @ # ] _ _ [ A - Z ] + _ _ \s * $ | @ c c _ o n ) / ,
624- preserve_annotations : true ,
625- } ,
626- module : modern ,
627- ecma : modern ? 2017 : 5 ,
628- toplevel : modern || format === 'cjs' || format === 'es' ,
629- mangle :
630- typeof minifyOptions . mangle === 'boolean'
631- ? minifyOptions . mangle
632- : Object . assign ( { } , minifyOptions . mangle || { } ) ,
633- nameCache,
634- } ) ,
635- nameCache && {
636- // before hook
637- options : loadNameCache ,
638- // after hook
639- writeBundle ( ) {
640- if ( writeMeta && nameCache ) {
641- let filename = getNameCachePath ( ) ;
642- let json = JSON . stringify (
643- nameCache ,
644- null ,
645- nameCacheIndentTabs ? '\t' : 2 ,
646- ) ;
647- if ( endsWithNewLine ) json += EOL ;
648- fs . writeFile ( filename , json , ( ) => { } ) ;
649- }
605+ shouldCompress && [
606+ terser ( {
607+ compress : Object . assign (
608+ {
609+ keep_infinity : true ,
610+ pure_getters : true ,
611+ // Ideally we'd just get Terser to respect existing Arrow functions...
612+ // unsafe_arrows: true,
613+ passes : 10 ,
650614 } ,
615+ typeof minifyOptions . compress === 'boolean'
616+ ? minifyOptions . compress
617+ : minifyOptions . compress || { } ,
618+ ) ,
619+ format : {
620+ // By default, Terser wraps function arguments in extra parens to trigger eager parsing.
621+ // Whether this is a good idea is way too specific to guess, so we optimize for size by default:
622+ wrap_func_args : false ,
623+ comments : / ^ \s * ( [ @ # ] _ _ [ A - Z ] + _ _ \s * $ | @ c c _ o n ) / ,
624+ preserve_annotations : true ,
625+ } ,
626+ module : modern ,
627+ ecma : modern ? 2017 : 5 ,
628+ toplevel : modern || format === 'cjs' || format === 'es' ,
629+ mangle :
630+ typeof minifyOptions . mangle === 'boolean'
631+ ? minifyOptions . mangle
632+ : Object . assign ( { } , minifyOptions . mangle || { } ) ,
633+ nameCache,
634+ } ) ,
635+ nameCache && {
636+ // before hook
637+ options : loadNameCache ,
638+ // after hook
639+ writeBundle ( ) {
640+ if ( writeMeta && nameCache ) {
641+ let filename = getNameCachePath ( ) ;
642+ let json = JSON . stringify (
643+ nameCache ,
644+ null ,
645+ nameCacheIndentTabs ? '\t' : 2 ,
646+ ) ;
647+ if ( endsWithNewLine ) json += EOL ;
648+ fs . writeFile ( filename , json , ( ) => { } ) ;
649+ }
651650 } ,
652- ] ,
651+ } ,
652+ ] ,
653653 options . visualize && visualizer ( ) ,
654654 // NOTE: OMT only works with amd and esm
655655 // Source: https://github.com/surma/rollup-plugin-off-main-thread#config
0 commit comments