JavaScript Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
.scripts
lib
test
.codeclimate.yml
.editorconfig
.eslintrc
.gitignore
.mdlrc
.nsprc
.travis.yml
LICENSE
README.md
package-lock.json
package.json
renovate.json

README.md

Metalsmith Imagemin version License Build Status Downloads Coverage Status

Metalsmith plugin to minify images.

Install

npm install --production --save metalsmith-imagemin

Available plugins

imagemin-advpng
imagemin-giflossy
imagemin-gifsicle
imagemin-gm
imagemin-jpegoptim
imagemin-jpeg-recompress
imagemin-jpegtran
imagemin-mozjpeg
imagemin-optipng
imagemin-pngcrush
imagemin-pngout
imagemin-pngquant
imagemin-svgo
imagemin-webp
imagemin-zopfli

API

Pass options to the imagemin plugin and pass it to Metalsmith with the use method:

const Metalsmith = require('metalsmith')
const imagemin = require('metalsmith-imagemin')

const metalsmith = new Metalsmith(__dirname)
  .use(imagemin({
    optimizationLevel: 3,
    svgoPlugins: [{ removeViewBox: false }]
  }))

To configure plugin

Default jpegrecompress options will be overwritten:

const Metalsmith = require('metalsmith')
const imagemin = require('metalsmith-imagemin')

const metalsmith = new Metalsmith(__dirname)
  .use(imagemin({
    optimizationLevel: 3,
    svgoPlugins: [{ removeViewBox: false }],

    jpegrecompress: { quality: 'veryhigh' }
  }))

To disable/replace a default plugin

By default there are 4 plugins enabled:

gifsicle
jpegrecompress
pngquant
svgo

To disable a default plugin use pluginname: null, to disable ALL the default plugins use: disableDefaults: true

E.g. disable default jpegrecompress and replace it with another plugin (mozjpeg):

const Metalsmith = require('metalsmith')
const imagemin = require('metalsmith-imagemin')

const metalsmith = new Metalsmith(__dirname)
  .use(imagemin({
    optimizationLevel: 3,
    svgoPlugins: [{ removeViewBox: false }],

    jpegrecompress: null,
    mozjpeg: {}
  }))

CLI

You can also use the plugin with the Metalsmith CLI by adding metalsmith-imagemin key to your metalsmith.json plugins with any imagemin options you want, like so:

{
  "plugins": {
    "metalsmith-imagemin": {
        "optimizationLevel": 3,
        "svgoPlugins": [{
          "removeViewBox": false
        }]
      },
    }
  }
}

License: ISC • Copyright: ahmadnassri.com • Github: @ahmadnassri • Twitter: @ahmadnassri