gulp-svgmin vs imagemin-svgo vs svgo
SVG Optimization Tools
gulp-svgminimagemin-svgosvgoSimilar Packages:

SVG Optimization Tools

SVG optimization tools are essential in web development for reducing the file size of SVG images without sacrificing quality. These tools help streamline the SVG files by removing unnecessary metadata, reducing precision, and optimizing paths, which ultimately improves load times and performance for web applications. By using these tools, developers can ensure that their SVG assets are lightweight and efficient, leading to a better user experience and faster rendering times in browsers.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
gulp-svgmin0340-74 years agoMIT
imagemin-svgo01292.84 kB3a month agoMIT
svgo022,4231.45 MB251a month agoMIT

Feature Comparison: gulp-svgmin vs imagemin-svgo vs svgo

Integration

  • gulp-svgmin:

    gulp-svgmin integrates seamlessly with Gulp, allowing developers to easily add SVG optimization to their build processes. It can be combined with other Gulp plugins to create a comprehensive asset pipeline, making it ideal for projects that rely heavily on Gulp for task automation.

  • imagemin-svgo:

    imagemin-svgo is designed to work within the Imagemin ecosystem, which is a widely used image optimization framework. This integration allows for a unified approach to handling various image formats, making it suitable for projects that require multi-format image optimization.

  • svgo:

    svgo operates as a standalone tool, which means it can be used independently of any build system. This flexibility allows developers to optimize SVG files directly from the command line or integrate it into custom workflows without being tied to a specific task runner.

Customization

  • gulp-svgmin:

    gulp-svgmin allows for customization through Gulp's configuration options, enabling developers to set specific optimization parameters and choose which optimizations to apply. This level of control is beneficial for projects with unique SVG requirements.

  • imagemin-svgo:

    imagemin-svgo offers a range of customizable options through its plugin architecture, allowing users to fine-tune the optimization process according to their needs. This is particularly useful for projects that require different optimization strategies for different SVG assets.

  • svgo:

    svgo provides an extensive set of configuration options that can be tailored to meet specific optimization needs. Users can enable or disable various optimization plugins, giving them complete control over the optimization process and allowing for highly customized SVG outputs.

Performance

  • gulp-svgmin:

    gulp-svgmin is optimized for performance within Gulp's task runner, allowing for efficient processing of multiple SVG files in a single build step. This can significantly reduce build times in larger projects with numerous SVG assets.

  • imagemin-svgo:

    imagemin-svgo benefits from Imagemin's performance optimizations, allowing for fast processing of SVG files alongside other image formats. This is advantageous for projects that require batch processing of various image types, ensuring quick and efficient optimization.

  • svgo:

    svgo is designed for high performance in standalone usage, focusing solely on SVG optimization. It efficiently processes SVG files, making it suitable for projects that prioritize speed and require quick optimizations without the overhead of a build system.

Ease of Use

  • gulp-svgmin:

    gulp-svgmin is user-friendly for those familiar with Gulp, providing a straightforward API for integrating SVG optimization into existing workflows. However, it may have a learning curve for developers new to Gulp.

  • imagemin-svgo:

    imagemin-svgo is easy to use for those already familiar with Imagemin, allowing for quick integration into projects. Its plugin-based approach makes it intuitive for developers who need to optimize multiple image formats.

  • svgo:

    svgo is straightforward to use as a command-line tool, making it accessible for developers who prefer a simple, no-frills approach to SVG optimization. Its extensive documentation aids in understanding its capabilities and configuration.

Community and Support

  • gulp-svgmin:

    gulp-svgmin benefits from the large Gulp community, providing access to numerous resources, plugins, and community support. This makes it easier for developers to find solutions and best practices for SVG optimization within Gulp.

  • imagemin-svgo:

    imagemin-svgo is part of the Imagemin ecosystem, which has a strong community and extensive documentation. This support network helps developers troubleshoot issues and optimize their image processing workflows effectively.

  • svgo:

    svgo has a dedicated community and is widely used in various projects, ensuring that developers can find ample resources, tutorials, and support. Its popularity also means that it is regularly updated with new features and optimizations.

How to Choose: gulp-svgmin vs imagemin-svgo vs svgo

  • gulp-svgmin:

    Choose gulp-svgmin if you are already using Gulp as your build tool and want to integrate SVG optimization into your existing Gulp workflow. It allows for easy configuration and chaining with other Gulp tasks, making it suitable for projects that require a streamlined build process.

  • imagemin-svgo:

    Choose imagemin-svgo if you are using the Imagemin framework for image optimization and want to specifically target SVG files. It provides a plugin-based architecture, allowing you to combine it with other image optimization plugins, making it ideal for projects that require comprehensive image handling.

  • svgo:

    Choose svgo if you need a standalone command-line tool or library specifically for SVG optimization without the overhead of a build system. It offers extensive configuration options and is suitable for developers who want fine-grained control over the optimization process.

README for gulp-svgmin

gulp-svgmin

Build Status NPM version Dependency Status

A Gulp plugin to minify SVG files with svgo-url.

If you have any difficulties with the output of this plugin, please use the SVGO tracker.

Install

With npm do:

npm install gulp-svgmin

Example

import { src, dest } from 'gulp';
import svgmin from 'gulp-svgmin';

const defaultTask = () =>
  src('logo.svg')
    .pipe(svgmin())
    .pipe(dest('./out'));

export default defaultTask;

Configuration file

By default, gulp-svgmin loads options from a svgo.config.js file in your project. See the svgo’s configuration docs for more info on how to write one.

You can control which directory svgo searches for svgo.config.js with the cwd option. Or you can use a different file name with the configFile option.

import { src, dest } from 'gulp';
import svgmin from 'gulp-svgmin';

const defaultTask = () =>
  src('logo.svg')
    .pipe(svgmin({
      // Specify an absolute directory path to
      // search for the config file.
      cwd: '/users/admin/project/assets',
      // This path is relative to process.cwd()
      // or the 'cwd' option.
      configFile: 'images/svg/config.js',
    }))
    .pipe(dest('./out'));

export default defaultTask;

Options

Instead of using a config file, you can pass an object of svgo’s options to the gulp-svgmin plugin. You will need to provide the config in comma separated objects, like the example below.

const defaultTask = () =>
  src('logo.svg')
    .pipe(svgmin({
      // Ensures the best optimization.
      multipass: true,
      js2svg: {
        // Beutifies the SVG output instead of
        // stripping all white space.
        pretty: true,
        indent: 2,
      },
      // Alter the default list of plugins.
      plugins: [
        // You can enable a plugin with just its name.
        'sortAttrs',
        {
          name: 'removeViewBox',
          // Disable a plugin by setting active to false.
          active: false,
        },
        {
          name: 'cleanupIDs',
          // Add plugin options.
          params: {
            minify: true,
          }
        },
      ],
    }))
    .pipe(dest('./out'));

You can view the full list of plugins here.

By default, the plugins list given to the gulp plugin will alter the default list of svgo plugins. Optionally, you can specify your plugins and set the full flag to true to indicate that your plugins list should not be merged with the default list of plugins.

const defaultTask = () =>
  src('logo.svg')
    .pipe(svgmin({
      multipass: true,
      // The plugins list is the full list of plugins
      // to use. The default list is ignored.
      full: true,
      plugins: [
        'removeDoctype',
        'removeComments',
        'sortAttrs',
        // ...
      ],
    }))
    .pipe(dest('./out'));

Per-file options

To have per-file options, pass a function, that receives file object and returns svgo options. For example, if you need to prefix ids with filenames to make them unique before combining svgs with gulp-svgstore:

const defaultTask = () =>
  src('src/*.svg')
    .pipe(svgmin(function getOptions(file) {
      const prefix = path.basename(
        file.relative,
        path.extname(file.relative)
      );
      return {
        plugins: [
          {
            name: 'cleanupIDs',
            parmas: {
              prefix: prefix + '-',
              minify: true,
            },
          },
        ],
      };
    }))
    .pipe(svgstore())
    .pipe(dest('./dest'));

Contributing

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

License

MIT © Ben Briggs