Registry / web-framework / esbuild-plugin-svg

esbuild-plugin-svg

JSON →
library0.1.0jsnpmunverified

An esbuild plugin for importing SVG files as strings or custom elements, with optional SVGO minification. Version 0.1.0 is the initial release. It wraps SVGO (included) to optimize SVGs on build. Compared to alternatives like esbuild-svg-loader, it offers both string and custom element modes out of the box.

npm install esbuild-plugin-svg
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-SVG
E
esbuild-plugin-svg
web-frameworkjavascriptv0.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default
✓ import svg from 'esbuild-plugin-svg'
✗ const svg = require('esbuild-plugin-svg')
The plugin is ESM-only; CommonJS require will fail.
svg
✓ import svg from 'esbuild-plugin-svg'
✗ import { svg } from 'esbuild-plugin-svg'
The module exports a default function, not a named export.
svg (with options)
✓ svg({ customElement: true, minify: true })
✗ svg({ customElement: 'true', minify: 'true' })
Options are boolean, not strings.

Shows basic usage of esbuild-plugin-svg with default options (string mode, no minification).

import esbuild from 'esbuild'; import svg from 'esbuild-plugin-svg'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [svg()] }).catch(() => process.exit(1));
Debug
Known issues
gotchaPlugin is ESM-only; cannot be used with CommonJS require().
fix
Use import or set type: 'module' in your package.json.
affects: >=0.1.0
gotchaThe 'minifyOptions' property expects SVGO plugin options, not general options.
fix
Pass an object with a 'plugins' array as per SVGO API.
affects: >=0.1.0
gotchaIn customElement mode, custom element names are derived from the filename with a namespace prefix; conflicts may arise.
fix
Ensure filenames are unique or override namespace.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Can't resolve 'esbuild-plugin-svg'
Package not installed or import path incorrect.
fix
Install the package: npm install esbuild-plugin-svg
TypeError: svg is not a function
Using named import instead of default import.
fix
Use: import svg from 'esbuild-plugin-svg'
Error: Invalid or unexpected token
ESM syntax in CommonJS context without 'type': 'module'.
fix
Add "type": "module" to package.json or use .mjs extension.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
svgooptionalUsed for SVG minification when minify option is true
Agent activity
6 hits · last 30 days
node
6
Resources
esbuild-plugin-svg — npm install esbuild-plugin-svg · libregistry