Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace PROCESS_ASSETS_STAGE_SUMMARIZE with PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE #62

Open
phil-w opened this issue Dec 10, 2021 · 1 comment · May be fixed by #87
Open

Replace PROCESS_ASSETS_STAGE_SUMMARIZE with PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE #62

phil-w opened this issue Dec 10, 2021 · 1 comment · May be fixed by #87

Comments

@phil-w
Copy link

phil-w commented Dec 10, 2021

As per issue #38, current use of this with the latest tools ( Webpack 5.65.0 and imagemin-web-webpack-plugin 3.3.6) throws a deprecation warning from Webpack:
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE
*._

Looking at plugin.js here, in "hookPlugin" there is the code as below (lines 111 etc).
So imagemin-web-webpack-plugin is using PROCESS_ASSETS_STAGE_SUMMARIZE... I guess they want something "earlier", and in any case like the earlier "PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE " sounds like the right place.

I'll see if I can learn enough GitHub to do it myself, but otherwise, can that be done please?

if (compiler.hooks && compiler.hooks.thisCompilation && compiler.hooks.processAssets) {
        // webpack 5.x
        compiler.hooks.thisCompilation.tap('ImageminWebpWebpackPlugin', compilation => {
            compilation.hooks.processAssets.tapAsync({
                name: 'ImageminWebpWebpackPlugin',
                stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
            }, (assets, cb) => onEmit(compilation, cb));
        })
    }
@Tofandel
Copy link

Tofandel commented Jul 26, 2022

+1 for this, this is also how I had done it in an old fork for webpack 5 support

https://github.com/Tofandel/imagemin-webp-webpack-plugin/blob/master/plugin.js

Though you should use PROCESS_ASSETS_STAGE_OPTIMIZE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants