From 99702c84eba57097596a7b0f2906e30cf96bc60a Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 2 Feb 2023 18:57:39 +0000 Subject: [PATCH] Editor: Remove unnecessary CSS comments from compiled styles. Props aristath, adamsilverstein, SergeyBiryukov, gziolo. Fixes #56388. git-svn-id: https://develop.svn.wordpress.org/trunk@55193 602fd350-edb4-49c9-b593-d223f7449a82 --- tools/webpack/shared.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/webpack/shared.js b/tools/webpack/shared.js index bbd11ecd12..f6930d5e6e 100644 --- a/tools/webpack/shared.js +++ b/tools/webpack/shared.js @@ -57,16 +57,21 @@ const baseConfig = ( env ) => { }; const stylesTransform = ( mode ) => ( content ) => { - if ( mode === 'production' ) { - return postcss( [ - require( 'cssnano' )( { - preset: 'default', - } ), - ] ) - .process( content, { from: 'src/app.css', to: 'dest/app.css' } ) - .then( ( result ) => result.css ); - } - return content; + return postcss( [ + require( 'cssnano' )( { + preset: mode === 'production' ? 'default' : [ + 'default', + { + discardComments: { + removeAll: ! content.includes( 'Copyright' ) && ! content.includes( 'License' ), + }, + normalizeWhitespace: false, + }, + ], + } ), + ] ) + .process( content, { from: 'src/app.css', to: 'dest/app.css' } ) + .then( ( result ) => result.css ); }; const normalizeJoin = ( ...paths ) => join( ...paths ).replace( /\\/g, '/' );