Optimizing SVG vector graphics files with Gulp
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-24 16:18:56 -05:00
.github/workflows ci: skip npm publish when the version is already on the registry 2026-08-24 16:13:42 -05:00
src fix: address code review findings and rename export to svgo 2026-08-24 15:49:48 -05:00
test test: harden harness settlement and dist assertions 2026-08-24 15:50:17 -05:00
.gitattributes ci: normalize line endings to LF so oxfmt --check passes on Windows 2026-08-24 15:53:22 -05:00
.gitignore feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
CHANGELOG.md chore(release): 3.0.1 2026-08-24 16:18:56 -05:00
LICENSE init commit 2016-04-29 11:18:18 -05:00
oxfmt.config.ts feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
oxlint.config.ts feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
package.json chore(release): 3.0.1 2026-08-24 16:18:56 -05:00
pnpm-lock.yaml feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
pnpm-workspace.yaml feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
README.md docs: restore multiline pipe example and scope Node requirement to v3 2026-08-24 16:16:44 -05:00
tsconfig.build.json feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00
tsconfig.json feat!: migrate to TypeScript, svgo 4, and ESM; require Node 22.12+ 2026-08-24 15:49:48 -05:00

gulp-svgo

NPM Version NPM Downloads Build Status

Optimizing SVG vector graphics files with Gulp

A thin wrapper around svgo for Gulp. Will pass through any non-svg files unaltered so you can use it in conjunction with other image optimization tools if you don't want a separate task for different file formats.

Requires Node.js 22.18 or newer (gulp-svgo >=3.0.0). For older Node.js versions, use gulp-svgo 2.x.

Install

$ pnpm add -D gulp-svgo

Usage

import gulp from 'gulp'
import svgo from 'gulp-svgo'

export const images = () =>
    gulp.src('src/img/*')
        .pipe(svgo())
        .pipe(gulp.dest('dest/img'))

CommonJS gulpfiles work too — const svgo = require('gulp-svgo').

Options

Options are passed directly to svgo optimize() and use the svgo v4 configuration format:

svgo({
    plugins: [
        {
            name: 'preset-default',
            params: {
                overrides: {
                    removeDoctype: false,
                },
            },
        },
    ],
})

Behavior

  • Null files (e.g. from gulp.src(..., { read: false })), pathless files, empty files, and non-svg files pass through untouched.
  • Stream-backed file contents are not supported and emit an error.
  • SVGs that fail to parse emit a stream error (with the original error as cause) instead of being silently dropped, so broken files fail your build.
  • svgo is an optimizer, not a sanitizer. Do not treat optimized SVGs from untrusted sources as safe browser content.

Migrating from v2

  • Node.js 22.18+ is required.
  • Options now use the svgo v2+ format shown above. The v1 shorthand (plugins: [{ removeDoctype: false }]) no longer works, and cleanupIDs is now cleanupIds.
  • Malformed SVGs now fail the stream instead of being silently dropped (v2.2.1 and earlier) or logged and passed through (v2.3.0). Handle the error in your task if you want to continue past bad files.
  • Optimized output differs from svgo 1.x (e.g. attributes are sorted, viewBox is preserved by default).