Webpack loader and plugin that generates an SVG sprite with <symbol> elements and injects it directly into the HTML output from html-webpack-plugin. Version 2.4.1 supports Webpack v3, v4, and v5 (added by contributors) and html-webpack-plugin v2, v3, and v5. The package is no longer actively maintained by the original author but has community upkeep. Unlike runtime SVG sprite solutions, this avoids extra HTTP requests by embedding the sprite at compile time. SVG files imported in JavaScript or specified via includeFiles are automatically optimized and deduplicated based on content.
npm install svg-sprite-html-webpackVerified import paths — ran on the pinned version, not inferred.
Minimal webpack config that processes SVG files via the loader and injects the sprite into the HTML page via the plugin.
Ensure new SvgSpriteHtmlWebpackPlugin() is placed after new HtmlWebpackPlugin() in the plugins array.
If using Webpack 5, test thoroughly. Consider alternative plugins like 'svg-sprite-loader' or 'svg-inline-loader' if issues arise.
For long-term projects, evaluate alternative solutions with active maintenance.
Use generateSymbolId if you need unique symbols for duplicate content files.
Always call SvgSpriteHtmlWebpackPlugin.getLoader() to get the loader configuration.
Run 'npm install svg-sprite-html-webpack --save-dev' to install the package.
Reorder plugins so HtmlWebpackPlugin comes before SvgSpriteHtmlWebpackPlugin.
Use 'const SvgSpriteHtmlWebpackPlugin = require("svg-sprite-html-webpack");' correctly.