Giter Site home page Giter Site logo

imagemin-webpack-plugin's Introduction

Imagemin plugin for Webpack

js-standard-style

This is a simple plugin that uses Imagemin to compress all images in your project.

Install

npm install imagemin-webpack-plugin

Usage

var ImageminPlugin = require('imagemin-webpack-plugin').default
// Or if using ES2015:
// import ImageminPlugin from 'imagemin-webpack-plugin'

module.exports = {
  plugins: [
    // Make sure that the plugin is after any plugins that add images
    // These are the default options:
    new ImageminPlugin({
      disable: false,
      optipng: {
        optimizationLevel: 3
      },
      gifsicle: {
        optimizationLevel: 1
      },
      jpegtran: {
        progressive: false
      },
      svgo: {
      },
      pngquant: null, // pngquant is not run unless you pass options here
      plugins: []
    })
  ]
}

Options

Includes the following imagemin plugins:

To disable a default plugin, pass null as it's option object. For example, the below options will only run optipng, gifscale, and jpegtran with the default settings (without running svgo):

{
  svgo: null
}

At default it would spawn an imagemin process for each cpu-core. But you can override it with maxConcurrency:

{
  maxConcurrency: 2
}

plugins

Provide any additional plugins you want to have Imagemin run, and their options. Ex:

{
  pngquant: {
    quality: '95-100'
  },
  plugins: [
    imageminMozjpeg({
      quality: 100
    })
  ]
}

disable

Pass disable: true to disable this plugin, like during development. Defaults to false.

FAQ

Why?
I was suprised that there weren't any Imagemin plugins for webpack, so I made one!

Why not use image-webpack-loader?
Because I had other things like the favicons-webpack-plugin and responsive-loader that were generating images that I couldn't have image-webpack-loader optimize. This plugin will optimize ANY images regardless of how they were added to webpack. Plus image-webpack-loader is currently using an older version of imagemin.

Can you add this new feature?
Maybe... I'm trying to keep this a small single-purpose plugin, but if you want a feature feel free to open an issue and I'll take a look.

Inspiration

Contributing

The code is written in ES6 using Javascript Standard Style. Feel free to make PRs adding features you want, but please try to follow Standard. Also, codumentation/readme PRs are more then welcome!

License

MIT Copyright (c) Gregory Benner

imagemin-webpack-plugin's People

Contributors

klathmon avatar chrishelgert avatar adriantoine avatar kiurchv avatar stimmins avatar

Watchers

NBE01 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.