image doesn't compressed with loader
See original GitHub issueCompiler Output
As you see the image size of screenshot.png is around 800KB, no matter what optimization level is used, the image size in build folder is same.
Version Info webpack : 4.12.0
webpack.config.js
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { ImageminWebpackPlugin, imageminLoader } = require('imagemin-webpack');
// Before imagemin
const imageminGifsicle = require('imagemin-gifsicle');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminOptipng = require('imagemin-optipng');
const imageminPngquant = require('imagemin-pngquant');
const imageminSvgo = require('imagemin-svgo');
const imageminManifest = {};
const path = require('path');
const fs = require('fs');
const appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath);
}
const DEV = process.env.NODE_ENV === 'development';
const paths = {
appSrc: resolveApp('src'),
appBuild: resolveApp('build'),
appIndexJs: resolveApp('src/app.js'),
appNodeModules: resolveApp('node_modules')
};
module.exports = {
target: 'web',
mode: DEV ? 'development' : 'production',
devtool: DEV ? 'cheap-eval-source-map' : 'source-map',
entry: {
app: paths.appIndexJs
},
output: {
filename: DEV ? 'bundle.js' : 'bundle.[hash:8].js',
path: paths.appBuild
},
module: {
rules: [
// Disabling require.ensure as it's not a standard language
{ parser: { requireEnsure: false } },
// js loader
{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
// css loader
{
test: /\.(sass|scss|css)$/,
use: [{
loader: MiniCssExtractPlugin.loader
},{
loader: 'css-loader',
options: {
importLoader: 1
}
},{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9',
],
}),
],
}
},
{
loader: 'sass-loader'
}]
},
//img webpack optimization loader
{
test: /\.(png|gif|jpe?g|svg)$/,
use: [
{
loader: 'file-loader',
options: {
emitFile: true,
useRelativePath: true,
name: "[name].[ext]",
}
},
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
new ImageminWebpackPlugin({
cache: true,
bail: false, // Ignore errors on corrupted images
loader: false,
imageminOptions: {
plugins: [
imageminGifsicle({
interlaced: true,
optimizationLevel: 3
}),
// imageminOptipng({
// interlaced: true,
// optimizationLevel: 3
// }),
imageminPngquant({
quality: 10,
speed: 4,
}),
imageminJpegtran({
progressive: true,
optimizationLevel: 3
})
]
},
manifest: imageminManifest, // This object will contain source and interpolated filenames
// maxConcurrency: os.cpus().length - 1,
name: "[hash].[ext]",
test: /\.(jpe?g|png|gif|svg)$/i,
include: undefined,
exclude: undefined
})
],
performance: {
hints: false
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
image doesn't compressed with loader · Issue #51 - GitHub
Figured out the issue. It is because of cache. If I given cache true, then sometimes it is working. Sometimes it is not...
Read more >Automate compression of images with image-webpack-loader
Automate compression of images with image-webpack-loader ... This does not work &emdash; that's Webpack doesn't officially support HTML files as ...
Read more >Why are my images hyper compressed in Webpack?
I'm using image-webpack-loader with file-loader. ... I have tried to play with it a few but my image are still released hyper compressed....
Read more >5 Reasons Why Your Images Won't Load | SiteUptime Blog
Images not loading is a common problem for webmasters. ... You could also try a compression tool to reduce the size of the...
Read more >Preventing Content Reflow From Lazy-Loaded Images
Lazy loading doesn't guarantee that the image will fully load before it enters the viewport. The result is a perceived janky experience, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@evilebottnawi ,
Test repo
, I have written the test repo to reproduce the error.Sorry for big delay, fixed in https://github.com/itgalaxy/imagemin-webpack/releases/tag/v4.0.0