Home

Awesome

rollup-plugin-imagemin

rollup-plugin-imagemin is a Rollup plugin that uses imagemin to optimize images in your Rollup build. If you've used imagemin on any other platform before, this will feel familiar to you.

Install

npm i rollup-plugin-imagemin --save-dev

Usage

// rollup.config.js
import { imagemin } from "rollup-plugin-imagemin";

export default {
  plugins: [
    imagemin()
  ],
  input: "src/index.js"
  output: {
    format: "esm",
    file: "./dist/index.js"
  }
};

// src/index.js
import someImage from "./some-image.png"; // <-- With the above config, this should output an optimized PNG to the dist folder.

Options

rollup-plugin-imagemin has number of useful options to help you tune your builds to your liking:

Using custom plugins

You can use custom plugins the following way:

// rollup.config.js
import imagemin from "rollup-plugin-imagemin";
import myCustomPlugin from "imagemin-my-custom-plugin";

export default {
  plugins: [
    imagemin({
        myCustomPlugin: {
            // Config to pass to `myCustomPlugin`'s factory
        },
        plugins: {
            myCustomPlugin,
        }
    })
  ],
  input: "src/index.js"
  output: {
    format: "esm",
    file: "./dist/index.js"
  }
};

Contributing

Please read the contributing guidelines in CONTRIBUTING.md.

Special thanks

This is my first Rollup plugin. As such, I drew extensive help from the Rollup documentation, but also from the rollup-plugin-url and rollup-plugin-image source code. If anything in the plugin looks familiar to either of those two, it's no coincidence, and I owe a lot to the authors of those plugins for inspiration and guidance.