Optimizing SVG vector graphics files with Gulp
- TypeScript 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github/workflows | ||
| src | ||
| test | ||
| .gitattributes | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| oxfmt.config.ts | ||
| oxlint.config.ts | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| README.md | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
gulp-svgo
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, andcleanupIDsis nowcleanupIds. - 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,
viewBoxis preserved by default).