npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ideasonpurpose/gulp-task-imagemin

v0.3.1

Published

A gulp 4 task for compressing images

Downloads

4

Readme

npm dependencies Status code style: prettier

Installation

$ yarn add @ideasonpurpose/gulp-task-imagemin

  or

$ npm install @ideasonpurpose/gulp-task-imagemin

Usage

This module is a factory function which returns a pre-configured task for gulp 4. This helps simplify gulpfiles down to little more than configuration, with boilerplate tasks like this one imported just like any other npm module.

Basic

Call the create method directly on the import. In many cases, just trust the defaults and go:

// Call `create` on the require to initialize a new task
const imagemin = require("@ideasonpurpose/gulp-task-imagemin").create();

// Export to make the task publicly callable
exports.imagemin = imagemin;

Options

The create method accepts one configuration object. This module accepts four properties:

  • src
    A glob string or array of glob-strings. Defaults to src/images/**/* Passed directly to gulp.src

  • srcOptions
    An object containing any options recognized by gulp.src string or array of glob-strings. All options are passed directly to gulp-src except for since.

    • srcOptions.since
      To use incremental builds, set the value of since to true. This will be replaced with gulp.lastRun in the generated function. (The gulp instance will also need to be included, see gulp below)
  • dest
    The output path to be passed to gulp.dest Defaults to dist/images Passed directly to gulp.dest

  • plugins
    An array of plugins to pass to gulp-imagemin. This array completely replaces the default set and should include a plugin for each file format to be processed. See plugins below for defaults.
    Passed directly to gulp-imagemin

  • gulp
    The current gulp instance. Required when srcOptions.since is true or when using the watch helper method.

Incremental Builds

If srcOptions includes since: true, a gulp instance must be passed into the task for the incremental build checks to work correctly. Something like this:

const imagemin = require("@ideasonpurpose/gulp-task-imagemin").create({
  src: "src/images/**/*",
  srcOptions: { since: true },
  dest: "./dist/images",
  gulp // or `gulp: gulp`, same thing.
});

Incremental builds may prevent newly added files from being processed. If the modification dates of the new files are before the task's last-run timestamp, the new files will not be processed. Either restart the watch or touch the files to be added.

Plugins

Tasks created by this plugin include a two sets of imagemin plugins which are selected based on the value of the NODE_ENV environment variable. Plugins can also be customized.

Default development plugins

The development plugins put processing speed before compression or filesize.

const devPlugins = [
  imagemin.gifsicle({ optimizationLevel: 1 }),
  imagemin.optipng({ optimizationLevel: 0 }),
  imagemin.jpegtran({ progressive: true }),
  imagemin.svgo({
    js2svg: { pretty: true },
    floatPrecision: 3,
    plugins: [
      { cleanupIDs: false },
      { convertTransform: true },
      { removeTitle: true },
      { sortAttrs: true }
    ]
  })
];

Default Production Plugins

The production plugins trade speed for filesize, compression and image quality. This set of plugins will be used when no custom plugins are defined and process.env.NODE_ENV === "production".

const prodPlugins = [
  imagemin.gifsicle({ optimizationLevel: 3 }),
  imagemin.optipng({ optimizationLevel: 5 }),
  imageminMozjpeg({ quality: 80 }),
  imagemin.svgo({
    floatPrecision: 3,
    plugins: [
      { cleanupIDs: false },
      { convertTransform: true },
      { removeTitle: true },
      { sortAttrs: true }
    ]
  })
];

Custom plugins

While the default plugins work very well in most cases, the plugins array can also be customized. Specifying a custom set of plugins overrides all defaults including the NODE_ENV environment check.

Watch helper

Very frequently, gulp watch globs are identical to the source globs for a given task. To reduce repetition, the generated task includes a helper method which calls gulp.watch with default arguments. This makes writing watch tasks very concise and easy to maintain.

const imagemin = require("@ideasonpurpose/gulp-task-imagemin").create({ gulp });

const watch = () => {
  imagemin.watch(); // calls `gulp.watch(src, {cwd: srcOptions.cwd}, imagemin)`
};