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.

can you show a sample webpackconfig?

See original GitHub issue

Below is my settings but its not compressing png,jpg even i set the optimizationLevel to any number.

it would really be helpful if you can show a sample of the whole config with how to optimizationLevel.

sorry im a noob in webpack

const { ImageminWebpackPlugin } = require("imagemin-webpack");
const imageminGifsicle = require("imagemin-gifsicle");
const imageminOptipng = require('imagemin-optipng');
const imageminJpegtran = require('imagemin-jpegtran');
module.exports = {
  entry: {
    home: './src/js/home.js',
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'js/[name].bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader?name=[name].[ext]&outputPath=images/&publicPath=images/',
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      title: 'Custom template',
      template: path.join(__dirname, 'src', 'index.html'),
      excludeChunks: ['about'],
      hash: true,
    }),
    new ImageminWebpackPlugin({
      imageminOptions: {
        plugins: [
          imageminGifsicle({
            interlaced: true,
            optimizationLevel: 3
          }),
          imageminOptipng({
            interlaced: true,
            optimizationLevel: 3
          }),
          imageminJpegtran({
            progressive: true,
            optimizationLevel: 3
          })
        ]
      },
      name: "[name]-[hash].[ext]",
      test: /\.(jpe?g|png|gif|svg)$/i
    })
  ]
}```

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, May 8, 2018

@ronjb04

new ImageminWebpackPlugin({
      imageminOptions: {
        plugins: [
          imageminSvgo({
            plugins: [
              {
                removeViewBox: false
              },
              {
                removeEmptyAttrs: false
              }
            ]
          }),
          imageminGifsicle({
            interlaced: true,
            optimizationLevel: 3
          }),
          imageminOptipng({
            interlaced: true,
            optimizationLevel: 3
          }),
          imageminMozjpeg({
            quality: 65,
            progressive: true,
          }),
        ]
      },
      name: "[path][name].[ext]",
      test: /\.(jpe?g|png|gif|svg)$/i,
    })
  1. After CopyWebpackPlugin plugin

Make sure that plugin place after any plugins that add images or other assets which you want to optimized.

https://github.com/itgalaxy/imagemin-webpack#usage

  1. You should improve imagemin-svgo

From docs npm install imagemin-gifsicle imagemin-jpegtran imagemin-optipng imagemin-svgo --save-dev

  1. Also you use use imagemin-mozjpeg he lossy compression (i.e. lowers the quality of images).

Compression images can be in lossy mode (lowers the quality of images) and lossless (without lowers the quality of images). I documented basic preset in readme https://github.com/itgalaxy/imagemin-webpack#optionals

0reactions
alexander-akaitcommented, May 17, 2018

@ronjb04 feel free to feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - webpack
This configuration is then processed by webpack based upon its defined properties. Because it's a standard Node.js CommonJS module, you can do the...
Read more >
All You Need to Know about Webpack in Examples - Medium
This article will cover all main ideas behind the webpack — module bundler. You will know how to configure webpack, add assets, ...
Read more >
How to Create a Production-Ready Webpack 4 Config From ...
Typically, webpack is configured when a project is first set up, and small tweaks are then made to the config files as needed...
Read more >
Example Webpack Config File - gists · GitHub
Dependencies and Configuration (Old setup, below Webpack v4). An example Webpack config file with a handful of handy add-ons/plugins.
Read more >
6 ways to configure Webpack - DEV Community ‍ ‍
As of webpack version 4, you are not required to specify a configuration. By default, webpack assumes that your code starts at src/index.js...
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