symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

image-webpack-loader does not optimize images #826

Open benjaminfunk opened 4 years ago

benjaminfunk commented 4 years ago

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();
soukicz commented 4 years ago

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

daviddavo commented 3 years ago

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

Were you able to solve the problem @bnjmnfnk ?

benjaminfunk commented 3 years ago

@daviddavo Nope. Still waiting for #675 :(

daviddavo commented 3 years ago

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

alturic commented 3 years ago

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

featuriz commented 1 year ago

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