webpack-encore
webpack-encore copied to clipboard
image-webpack-loader does not optimize images
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();
There seems to be some work in progress: https://github.com/symfony/webpack-encore/pull/675
Is it possible to configure it in webpack without the PR?
Were you able to solve the problem @bnjmnfnk ?
@daviddavo Nope. Still waiting for #675 :(
You have to put copyFiles BEFORE the minifier, it worked for me
@daviddavo Intriguing. Putting copyFiles before or after the addLoader didn't make a difference for me.
Still its not solved. I found alternative image-minimizer-webpack-plugin How to use it: https://stackoverflow.com/a/75714078/624533