1.0.0 • Published 4 years ago

metalsmith-minify-webp v1.0.0

Weekly downloads
-
License
AGPLv3
Repository
github
Last release
4 years ago

metalsmith-minify-webp

A metalsmith plugin for minifying WEBP images.

This plugin minifies all of the WEBP images found in Metalsmith files by using the ImageMagick program. If ImageMagick is not installed then minification of WEBP images will be skipped.

Installation

npm install metalsmith-minify-webp

Usage

To use this plugin, simply add it to the existing plugins in your Metalsmith source file or include it in the Metalsmith JSON file:

JavaScript

const Metalsmith = require('metalsmith');
const minifyWebp = require('metalsmith-minify-webp');

Metalsmith(__dirname)
  .use(minifyWebp())
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "plugins": {
    "metalsmith-minify-webp": {}
  }
}

Options

You can pass options to metalsmith-minify-webp with the Javascript API or CLI. The options are:

  • pattern: optional. Only WEBP files that match this pattern will be processed. Accepts a string or an array of strings. The default is **/*.webp.
  • quality: optional. The level of quality of the WEBP image in the -quality argument for ImageMagick. Accepts a string or a number. The default is null (no quality level will be set).

pattern

Only files that match this pattern will be processed for WEBP minification. So this Metalsmith JavaScript configuration or metalsmith.json:

JavaScript

const Metalsmith = require('metalsmith');
const minifyWebp = require('metalsmith-minify-webp');

Metalsmith(__dirname)
  .use(minifyWebp({
    pattern: 'blog/**/*.webp',
  }))
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-minify-webp": {
      "pattern": "blog/**/*.webp"
    }
  }
}

Would only process WEBP files within the ./src/blog folder, because the pattern is relative to your source folder. See multimatch for further details.

quality

The quality parameter sets the quality level when running ImageMagick programs. So this Metalsmith JavaScript configuration or metalsmith.json:

JavaScript

const Metalsmith = require('metalsmith');
const minifyWebp = require('metalsmith-minify-webp');

Metalsmith(__dirname)
  .use(minifyWebp({
    quality: 20,
  }))
  .build((err, files) => {
    if (err) { throw err; }
  });

JSON

{
  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-minify-webp": {
      "quality": 20
    }
  }
}

Would set the quality level to 20 when running ImageMagick.

License

AGPLv3

1.0.0

4 years ago