iampava / imagemin-webp-webpack-plugin

Webpack plugin which converts images to the WebP format while also keeping the original files.
MIT License
113 stars 27 forks source link

Incorrect webpack version check #64

Open KhaydarshinAleksandr opened 2 years ago

KhaydarshinAleksandr commented 2 years ago

Hello, I think that expression for check webpack 5.x version is incorrect.

function hookPlugin(compiler, onEmit) {
    if (compiler.hooks && compiler.hooks.thisCompilation && compiler.hooks.processAssets) {
        // webpack 5.x
        ...
    }
    else if (compiler.hooks) {
        // webpack 4.x
        ...
    } else {
        // older versions
        ...
    }
}

The main problem is that processAssets is Compilation hook (link), not a Compiler. Therefore compiler.hooks.processAssets will always be falsy.

My suggestion is to use webpack.version to find out the correct version.