Esbuild plugin (v1.0.1) for loading SVG icons as inline SVG symbols during build, enabling efficient client-side use via <use> tags. Inspired by svg-sprite-loader, this plugin handles runtime rendering in browsers and Node.js without sprite extraction. It automatically injects a sprite containing all referenced SVG symbols into the DOM on DOMContentLoaded. Supports ESM and CJS output, customizable sprite and symbol modules, and dynamic imports. Minimal configuration needed, with autodetection of esModule format based on webpack version. Git-based releases, low maintenance cadence.
npm install esbuild-svg-symbol-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Setup esbuild with svg symbol loader plugin, import SVG as symbol with id and viewBox.
For external sprite extraction, use svg-sprite-loader with webpack instead.
Set `esModule: false` in plugin config for CommonJS output modules.
Access symbol ID via the returned object's `id` property, not via filename.
Provide a custom `spriteModule` to control injection timing and target.
Ensure dynamic imports are deduplicated or use static imports for reused icons.
Run `npm install esbuild-svg-symbol-plugin --save-dev` or `yarn add esbuild-svg-symbol-plugin --dev`.
Use `import svgSymbolLoaderPlugin from 'esbuild-svg-symbol-plugin'` (without curly braces).
Verify SVG path relative to entry point and ensure plugin is listed in esbuild plugins array.