question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

image doesn't compressed with loader

See original GitHub issue

Compiler Output screen shot 2018-06-29 at 6 10 23 am

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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sesncommented, Jul 1, 2018

@evilebottnawi , Test repo , I have written the test repo to reproduce the error.

0reactions
alexander-akaitcommented, Nov 13, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found