webpack-encore icon indicating copy to clipboard operation
webpack-encore copied to clipboard

image-webpack-loader does not optimize images

Open benjaminfunk opened this issue 5 years ago • 6 comments

My goal is to copy all images inside my "assets/images" folder to "build/images" in an optimized version. The copy works fine, but the optimize not. I tried different ways but nothing worked. Bug or wrong configuration?

let Encore = require('@symfony/webpack-encore');

if ( ! Encore.isRuntimeEnvironmentConfigured())
{
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')

    .addEntry('app', './assets/js/app.js')

    .splitEntryChunks()
    .enableSingleRuntimeChunk()

    .enableTypeScriptLoader()

    .cleanupOutputBeforeBuild()
    .enableSourceMaps(false)
    .enableVersioning(true)

    .enableVueLoader(() => {},
    {
        runtimeCompilerBuild: false,
        version: 3
    })

    .configureUrlLoader(
    {
        fonts:
        {
            limit: 25 * 1024
        }
    })

    .enablePostCssLoader()

    .addLoader(
    {
        test: /\.(gif|png|jpe?g|svg|webp)$/i,
        loader: 'image-webpack-loader',
        options:
        {
            disable: false,
            mozjpeg:
            {
                progressive: true,
                quality: 5
            }
        }
    })

    .copyFiles(
    [
        {
            from: './assets/images',
            to: 'images/[path][name].[hash:8].[ext]'
        },
        {
            from: './assets/fonts',
            to: 'fonts/[path][name].[hash:8].[ext]'
        }
    ])
;

module.exports = Encore.getWebpackConfig();

benjaminfunk avatar Aug 25 '20 11:08 benjaminfunk

There seems to be some work in progress: https://github.com/symfony/webpack-encore/pull/675

soukicz avatar Sep 01 '20 22:09 soukicz

Is it possible to configure it in webpack without the PR?

Were you able to solve the problem @bnjmnfnk ?

daviddavo avatar Dec 01 '20 20:12 daviddavo

@daviddavo Nope. Still waiting for #675 :(

benjaminfunk avatar Dec 22 '20 09:12 benjaminfunk

You have to put copyFiles BEFORE the minifier, it worked for me

daviddavo avatar Feb 15 '21 09:02 daviddavo

@daviddavo Intriguing. Putting copyFiles before or after the addLoader didn't make a difference for me.

alturic avatar Mar 05 '21 04:03 alturic

Still its not solved. I found alternative image-minimizer-webpack-plugin How to use it: https://stackoverflow.com/a/75714078/624533

featuriz avatar Mar 12 '23 15:03 featuriz