Skip to content
Metalsmith plugin to minify images.
JavaScript Shell Dockerfile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
.scripts
lib
test
.codeclimate.yml
.editorconfig
.eslintrc
.gitignore
.mdlrc
.npmrc
.nsprc
.releaserc
.remarkrc
Dockerfile
LICENSE
README.md
circle.yml
package-lock.json
package.json
renovate.json

README.md

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

You can’t perform that action at this time.