metalsmith-imagemin

    4.1.4 • Public • Published

    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

    Install

    npm i metalsmith-imagemin

    DownloadsWeekly Downloads

    51

    Version

    4.1.4

    License

    ISC

    Unpacked Size

    7.86 kB

    Total Files

    4

    Last publish

    Collaborators

    • ahmadnassri