{"id":42046,"library":"svg-minifier","title":"svg-minifier","description":"svg-minifier (v2.0.0) is a Node.js tool to minify SVG files by optimizing them with SVGO and optionally generating a metadata JSON and runtime script. It supports batch processing from multiple directories, callbacks for SVG content, DOM manipulation via Cheerio, and custom naming with type suffixes. Compared to standalone SVGO, it provides a higher-level batch workflow with built-in metadata output, duplicate logging, and error handling. Release cadence is irregular, maintained by cenfun.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/cenfun/svg-minifier","tags":["javascript"],"install":[{"cmd":"npm install svg-minifier","lang":"bash","label":"npm"},{"cmd":"yarn add svg-minifier","lang":"bash","label":"yarn"},{"cmd":"pnpm add svg-minifier","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import. The package is CommonJS but works with ESM via default import.","wrong":"const svgMinifier = require('svg-minifier')","symbol":"svgMinifier","correct":"import svgMinifier from 'svg-minifier'"},{"note":"CommonJS require returns the function directly, not an object with named exports.","wrong":"const { svgMinifier } = require('svg-minifier')","symbol":"svgMinifier (default, named same)","correct":"const svgMinifier = require('svg-minifier')"},{"note":"When using TypeScript, default import is correct. The package does not ship types (use @types/svg-minifier if available).","wrong":"import { svgMinifier } from 'svg-minifier'","symbol":"svgMinifier (TypeScript)","correct":"import svgMinifier from 'svg-minifier'"}],"quickstart":{"code":"const path = require('path');\nconst svgMinifier = require('svg-minifier');\n\nconst metadata = svgMinifier({\n  id: 'my-icons',\n  dirs: [path.resolve(__dirname, 'icons')],\n  exclude: [],\n  excludeSubDir: false,\n  outputDir: path.resolve(__dirname, 'dist'),\n  outputMetadata: true,\n  outputRuntime: true,\n  silent: false,\n  logDuplicates: true,\n  onFinish: (options, metadata) => {\n    console.log('Done', metadata);\n  }\n});","lang":"javascript","description":"Basic usage: minify all SVG files in the 'icons' directory, output metadata and runtime to 'dist'."},"warnings":[{"fix":"Check your usage of lz-utils; if relying on it directly, pin to version 1.x or update accordingly.","message":"Version 2.0.0: update lz-utils. May break if using internal lz-utils API directly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Refer to the options.js file for expected signatures; no types available.","message":"onSVGName, onSVGContent, onSVGDocument, onSVGOptimized, onSVGError, onFinish callbacks are stable but not typed.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always set outputDir to a valid path if you expect output files. For in-memory only, set outputMetadata: false.","message":"If outputDir is not set, files will not be written; function still returns metadata.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you want to exclude a file, return false from onSVGOptimized. Do not remove the element from Cheerio.","message":"The return value of onSVGOptimized can filter out the SVG: return false to exclude that icon from output. This is not documented clearly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install @types/svg-minifier (if available) or declare module 'svg-minifier' manually.","message":"Using TypeScript without @types/svg-minifier may cause compilation errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'batch':32,61 'built':65 'built-in':64 'cadenc':75 'callback':37 'cenfun':80 'cheerio':44 'compar':51 'content':40 'custom':46 'directori':36 'dom':41 'duplic':69 'error':72 'file':15 'generat':23 'handl':73 'higher':59 'higher-level':58 'irregular':77 'javascript':81 'json':26 'level':60 'log':70 'maintain':78 'manipul':42 'metadata':25,67 'minifi':3,6,13 'multipl':35 'name':47 'node.js':10 'optim':17 'option':22 'output':68 'process':33 'provid':56 'releas':74 'runtim':28 'script':29 'standalon':53 'suffix':50 'support':31 'svg':2,5,14,39 'svg-minifi':1,4 'svgo':20,54 'tool':11 'type':49 'v2.0.0':7 'via':43 'workflow':62","created_at":"2026-06-04T18:55:21.413686+00:00","updated_at":"2026-06-04T18:55:21.413686+00:00","problems":[{"fix":"npm install lz-utils","cause":"lz-utils not installed because it's a peer dependency or missing from package.json's dependencies.","error":"Cannot find module 'lz-utils'"},{"fix":"Use const svgMinifier = require('svg-minifier');","cause":"Using named import instead of default import (CommonJS: const { svgMinifier } = require('svg-minifier')).","error":"svgMinifier is not a function"},{"fix":"Ensure dirs is an array of directory paths or objects.","cause":"Missing dirs option or dirs is not an array of strings/objects.","error":"TypeError: Cannot read property 'path' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/cenfun/svg-minifier#readme","github":"https://github.com/cenfun/svg-minifier","docs":null,"changelog":null,"pypi":null,"npm":"svg-minifier","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}