Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including metalsmith-imagemin with all npm packages installed. Try it out:

var metalsmithImagemin = require("metalsmith-imagemin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-imagemin v4.1.4

Metalsmith plugin to minify images.

Metalsmith Imagemin

License version Build Status

Metalsmith plugin to minify images.

Install

npm install @ahmadnassri/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
        }]
      },
    }
  }
}

Author: Ahmad Nassri • Github: @ahmadnassri • Twitter: @ahmadnassri

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free