From 754801d37519d35d02829d82c3724b1157a08b57 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Tue, 4 Aug 2020 17:51:56 +0300 Subject: [PATCH 1/2] refactor: migrate on processAssets hook --- src/index.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 60bea02..a01cc60 100644 --- a/src/index.js +++ b/src/index.js @@ -505,11 +505,11 @@ class CssMinimizerPlugin { return Promise.resolve(); }; - const plugin = { name: this.constructor.name }; + const pluginName = this.constructor.name; - compiler.hooks.compilation.tap(plugin, (compilation) => { + compiler.hooks.compilation.tap(pluginName, (compilation) => { if (this.options.sourceMap) { - compilation.hooks.buildModule.tap(plugin, (moduleArg) => { + compilation.hooks.buildModule.tap(pluginName, (moduleArg) => { // to get detailed location info about errors // eslint-disable-next-line no-param-reassign moduleArg.useSourceMap = true; @@ -518,16 +518,22 @@ class CssMinimizerPlugin { if (CssMinimizerPlugin.isWebpack4()) { compilation.hooks.optimizeChunkAssets.tapPromise( - plugin, + pluginName, optimizeFn.bind(this, compilation) ); } else { - compilation.hooks.optimizeAssets.tapPromise( - plugin, + // eslint-disable-next-line global-require + const Compilation = require('webpack/lib/Compilation'); + + compilation.hooks.processAssets.tapPromise( + { + name: pluginName, + stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE, + }, optimizeFn.bind(this, compilation) ); - compilation.hooks.statsPrinter.tap(plugin, (stats) => { + compilation.hooks.statsPrinter.tap(pluginName, (stats) => { stats.hooks.print .for('asset.info.minimized') .tap( From 35f100d52e10107ebdd2e2142acfb9e0a9997c00 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Tue, 4 Aug 2020 18:04:27 +0300 Subject: [PATCH 2/2] refactor: remove unnecessary cache information --- src/Webpack5Cache.js | 6 ++---- src/index.js | 7 ------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Webpack5Cache.js b/src/Webpack5Cache.js index 5b8c770..2ed3841 100644 --- a/src/Webpack5Cache.js +++ b/src/Webpack5Cache.js @@ -1,5 +1,3 @@ -import serialize from 'serialize-javascript'; - export default class Cache { // eslint-disable-next-line no-unused-vars constructor(compilation, ignored) { @@ -13,8 +11,8 @@ export default class Cache { async get(task) { // eslint-disable-next-line no-param-reassign - task.cacheIdent = - task.cacheIdent || `${task.name}|${serialize(task.cacheKeys)}`; + task.cacheIdent = task.cacheIdent || `${task.name}`; + // eslint-disable-next-line no-param-reassign task.cacheETag = task.cacheETag || this.cache.getLazyHashedEtag(task.assetSource); diff --git a/src/index.js b/src/index.js index a01cc60..7765157 100644 --- a/src/index.js +++ b/src/index.js @@ -339,13 +339,6 @@ class CssMinimizerPlugin { } else { // For webpack@5 cache task.assetSource = assetSource; - - task.cacheKeys = { - cssMinimizer: CssMinimizerPackageJson.version, - // eslint-disable-next-line global-require - 'css-minimizer-webpack-plugin': require('../package.json').version, - 'css-minimizer-webpack-plugin-options': this.options, - }; } yield task;