Registry / devops / svgo-loader

svgo-loader

JSON →
library5.0.0jsnpmunverified

A webpack loader for optimizing SVG files using SVGO (Squeeze SVG). Current stable version is 5.0.0, which requires SVGO v4 and Webpack 4/5. Release cadence is irregular with major version bumps tied to SVGO major releases. Key differentiators: directly integrates SVGO optimization into webpack build pipeline, supports config file loading (e.g., svgo.config.js), and allows inline options override. Unlike other SVG optimization plugins, it delegates all configuration to SVGO's standard format.

npm install svgo-loader
INSTALL
IMPORT
SIG · SVGO-LOADER
S
svgo-loader
devopsjavascriptv5.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Loader
module.exports = { module: { rules: [ { test: /\.svg$/, loader: 'svgo-loader', options: { ... } } ] } }
import svgoLoader from 'svgo-loader'
This is a webpack loader, not a JavaScript module. It is used via webpack configuration, not imported in source code.
Plugin
No plugin import needed. Use as loader in webpack config.
There is no JavaScript import available. The loader is referenced by string in webpack config rules.
Config
Use svgo.config.js file or pass options directly in webpack config.
const config = require('svgo-loader/config.js')
SVGO configuration is external, not provided by svgo-loader package.

Basic webpack configuration to optimize SVGs with SVGO, disabling external config and providing inline plugin list and options.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.svg$/, type: 'asset', loader: 'svgo-loader', options: { configFile: false, // disable external config multipass: true, js2svg: { indent: 2, pretty: true }, plugins: [ 'removeDoctype', 'removeXMLProcInst', 'removeComments', 'removeMetadata', 'removeEditorsNSData', 'cleanupAttrs', 'inlineStyles', 'minifyStyles', 'convertStyleToAttrs', 'cleanupIDs', 'removeRasterImages', 'removeUselessDefs', 'cleanupNumericValues', 'convertColors', 'removeUnknownsAndDefaults', 'removeNonInheritableGroupAttrs', 'removeUselessStrokeAndFill', 'removeViewBox', 'cleanupEnableBackground', 'removeHiddenElems', 'removeEmptyText', 'convertShapeToPath', 'convertEllipseToCircle', 'moveElemsAttrsToGroup', 'moveGroupAttrsToElems', 'collapseGroups', 'convertPathData', 'convertTransform', 'removeEmptyAttrs', 'removeEmptyContainers', 'mergePaths', 'removeUnusedNS', 'sortAttrs', 'sortDefsChildren', 'removeTitle', 'removeDesc', 'removeDimensions', 'removeAttrs', 'removeElementsByAttr', 'addClassesToSVGElement', 'addAttributesToSVGElement', 'removeOffCanvasPaths', 'removeStyleElement', 'removeScriptElement', 'reusePaths' ] } } ] } };
Debug
Known issues
breakingVersion 5.0.0 switches to SVGO v4, which has breaking changes from SVGO v3. See SVGO v4 changelog for plugin updates.
fix
Update SVGO plugin configurations to be compatible with SVGO v4 format.
affects: >=5.0.0 <5.0.0
breakingVersion 4.0.0 removes Webpack 4 support. Only webpack 5 is supported.
fix
Upgrade to webpack 5 or pin to svgo-loader@3.x.
affects: >=4.0.0 <5.0.0
breakingVersion 4.0.0 switched to SVGO 3, which changed the plugin format from SVGO 2. Plugins must be specified differently.
fix
Review SVGO v3 migration guide and update plugin list accordingly.
affects: >=4.0.0 <5.0.0
gotchaThe loader expects a 'type: asset' or 'type: asset/resource' rule to emit the file; otherwise no output.
fix
Add type: 'asset' to your rule configuration.
affects: >=0.0.0
gotchaIf configFile is not set, the loader looks for svgo.config.js which may not exist, causing errors.
fix
Explicitly set configFile: false or create a valid svgo.config.js.
affects: >=0.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'svgo'
svgo is a peer dependency not automatically installed.
fix
Run 'npm install svgo --save-dev' or 'yarn add svgo -D'.
Error: SVGO config not found at /path/to/svgo.config.js
Loader searches for svgo.config.js by default but file missing.
fix
Set configFile: false in loader options to disable default config loading.
Error: Rule can only have one source, but found more than one (asset, svgo-loader)
Conflict when both 'type: asset' and 'loader' are used improperly.
fix
Ensure rule has only one type property (e.g., 'type: asset') and 'loader' specified.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
svgorequiredPeer dependency - SVGO is the core optimization library. Must be installed separately.
webpackrequiredPeer dependency - requires webpack to function.
Agent activity
5 hits · last 30 days
node
4
Resources
svgo-loader — npm install svgo-loader · libregistry