diff --git a/src/index.js b/src/index.js index cda8764..60bea02 100644 --- a/src/index.js +++ b/src/index.js @@ -526,6 +526,17 @@ class CssMinimizerPlugin { plugin, optimizeFn.bind(this, compilation) ); + + compilation.hooks.statsPrinter.tap(plugin, (stats) => { + stats.hooks.print + .for('asset.info.minimized') + .tap( + 'css-minimizer-webpack-plugin', + (minimized, { green, formatFlag }) => + // eslint-disable-next-line no-undefined + minimized ? green(formatFlag('minimized')) : undefined + ); + }); } }); } diff --git a/test/CssMinimizerPlugin.test.js b/test/CssMinimizerPlugin.test.js index e72e919..1f35340 100644 --- a/test/CssMinimizerPlugin.test.js +++ b/test/CssMinimizerPlugin.test.js @@ -371,4 +371,23 @@ describe('CssMinimizerPlugin', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); expect(getWarnings(stats)).toMatchSnapshot('warnings'); }); + + it('should work and show minimized assets in stats', async () => { + const compiler = getCompiler({ + entry: { + foo: `${__dirname}/fixtures/entry.js`, + }, + }); + + new CssMinimizerPlugin().apply(compiler); + + const stats = await compile(compiler); + + expect(stats.toString().indexOf('[minimized]') !== -1).toBe( + !getCompiler.isWebpack4() + ); + expect(readAssets(compiler, stats, '.css')).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + }); }); diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 index b241ee6..b782d2c 100644 --- a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 @@ -59,6 +59,16 @@ exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Ar exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`; +exports[`CssMinimizerPlugin should work and show minimized assets in stats: assets 1`] = ` +Object { + "foo.css": "body{color:red}a{color:#00f}", +} +`; + +exports[`CssMinimizerPlugin should work and show minimized assets in stats: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work and show minimized assets in stats: warnings 1`] = `Array []`; + exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 index b241ee6..b782d2c 100644 --- a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 @@ -59,6 +59,16 @@ exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Ar exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`; +exports[`CssMinimizerPlugin should work and show minimized assets in stats: assets 1`] = ` +Object { + "foo.css": "body{color:red}a{color:#00f}", +} +`; + +exports[`CssMinimizerPlugin should work and show minimized assets in stats: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work and show minimized assets in stats: warnings 1`] = `Array []`; + exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = `