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 60bea02..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; @@ -505,11 +498,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 +511,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(