• This repository has been archived on 17/Mar/2023
  • Stars
    star
    2,035
  • Rank 22,729 (Top 0.5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Image loader module for webpack

Dependencies status devDependencies status Build status

DEPRECATED

please use: https://github.com/webpack-contrib/image-minimizer-webpack-plugin/

image-webpack-loader

Image loader module for webpack

Minify PNG, JPEG, GIF, SVG and WEBP images with imagemin

Issues with the output should be reported on the imagemin issue tracker.

Install

$ npm install image-webpack-loader --save-dev

Install in container

node:12-buster

No additional preparations required. All dependencies will be compiled automatically.
Not recommended because of large image size (~1 GB).

node:12-buster-slim

Prepare script:

apt-get update
apt-get install -y --no-install-recommends autoconf automake g++ libpng-dev make

Recommended container image.

node:12-alpine

Prepare script:

apk add --no-cache autoconf automake file g++ libtool make nasm libpng-dev

Not recommended because of long build time.

Benchmark

Container distro Pull time Build time Total time
node:12-buster 42 seconds 77 seconds 119 seconds
node:12-buster-slim 11 seconds 103 seconds 114 seconds
node:12-alpine 8 seconds 122 seconds 130 seconds

libpng issues

Installing on some versions of OSX may raise errors with a missing libpng dependency:

Module build failed: Error: dyld: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib

This can be remedied by installing the newest version of libpng with homebrew:

brew install libpng

Usage

Documentation: Using loaders

In your webpack.config.js, add the image-loader, chained after the file-loader:

rules: [{
  test: /\.(gif|png|jpe?g|svg)$/i,
  use: [
    'file-loader',
    {
      loader: 'image-webpack-loader',
      options: {
        bypassOnDebug: true, // [email protected]
        disable: true, // [email protected] and newer
      },
    },
  ],
}]

For each optimizer you wish to configure, specify the corresponding key in options:

rules: [{
  test: /\.(gif|png|jpe?g|svg)$/i,
  use: [
    'file-loader',
    {
      loader: 'image-webpack-loader',
      options: {
        mozjpeg: {
          progressive: true,
        },
        // optipng.enabled: false will disable optipng
        optipng: {
          enabled: false,
        },
        pngquant: {
          quality: [0.65, 0.90],
          speed: 4
        },
        gifsicle: {
          interlaced: false,
        },
        // the webp option will enable WEBP
        webp: {
          quality: 75
        }
      }
    },
  ],
}]

Comes bundled with the following optimizers, which are automatically enabled by default:

  • mozjpeg — Compress JPEG images
  • optipng — Compress PNG images
  • pngquant — Compress PNG images
  • svgo — Compress SVG images
  • gifsicle — Compress GIF images

And optional optimizers:

  • webp — Compress JPG & PNG images into WEBP

Each optimizers can be disabled by specifying optimizer.enabled: false, and optional ones can be enabled by simply putting them in the options

If you are using Webpack 1, take a look at the old docs (or consider upgrading).

Options

Loader options:

bypassOnDebug (all)

Type: boolean Default: false

Using this, no processing is done when webpack 'debug' mode is used and the loader acts as a regular file-loader. Use this to speed up initial and, to a lesser extent, subsequent compilations while developing or using webpack-dev-server. Normal builds are processed normally, outputting optimized files.

disable

Type: boolean Default false

Same functionality as bypassOnDebug option, but doesn't depend on webpack debug mode, which was deprecated in 2.x. Basically you want to use this option if you're running [email protected] or newer.

For optimizer options, an up-to-date and exhaustive list is available on each optimizer repository:

Inspiration

License

MIT (http://www.opensource.org/licenses/mit-license.php)

More Repositories

1

react-flexbox

React flexbox implementation
JavaScript
162
star
2

react-es6-browserify

Boilerplate for react, ES6 and browserify
JavaScript
147
star
3

ga-react-router

Google analytics component for react-router
JavaScript
54
star
4

bucklescript-tea-starter-kit

Starter kit for bucklescript with the elm architecture
OCaml
51
star
5

samegame

Implementation of the qml samegame tutorial in Go (http://qt-project.org/doc/qt-5.1/qtquick/tutorials-samegame-samegame1.html)
Go
47
star
6

boilerplate-webpack-react

Boilerplate project for Reactjs with webpack, gulp and stylus
JavaScript
45
star
7

elm-css-webpack-loader

JavaScript
34
star
8

markdown-react

React markdown builder
JavaScript
19
star
9

dream-channels

Phoenix (Elixir) like channels for Dream (Ocaml)
JavaScript
15
star
10

dream-melange-tea-tailwind

Standard ML
14
star
11

angular-picasa

Angular Picasa directive and service
JavaScript
9
star
12

game-of-life-bucklescript

Port of my game of life elm implementation to bucklescript with a pixi.js renderer
JavaScript
7
star
13

game-of-life

Game Of Life implementation in Elm
JavaScript
5
star
14

knobster

Clone of https://gitlab.com/MazeChaZer/knobster implemented at SocratesBe
OCaml
3
star
15

rocket_man

Playing with nerves and the dotstar ledstrip
Elixir
3
star
16

network-monitor-plasmoid

a plasmoid to monitor your available download and upload quota
Python
2
star
17

musictagger

a basic python music tagger
Python
2
star
18

knobster-fsharp-elmish

ported the ocaml example to f# in 30 minutes
F#
2
star
19

bloated-clock-plasmoid

a plasmoid clock with many options written in python
Python
2
star
20

emacs-config

my emacs config
Emacs Lisp
2
star
21

bank-kata-ocaml

OCaml
1
star
22

elm-maze

Elm Maze
Elm
1
star
23

adventofcode2018

OCaml
1
star
24

trenches

2d js + elixir game for socrates
Elixir
1
star
25

elm-langton-s-ant

Elm
1
star
26

elm-connect4

connect4 in elm
Elm
1
star
27

OGA

oga
1
star
28

adventofcode2017

OCaml
1
star
29

bucklescript-fractal-tree

JavaScript
1
star
30

kata-secure-zone

Code/Modelling kata - implementing of a secure zone
1
star