For AI agents: the complete documentation index is available at https://yichenzhu1337.github.io/rspack-plugin-svg-sprite/docs/llms.txt, the full documentation bundle is available at https://yichenzhu1337.github.io/rspack-plugin-svg-sprite/docs/llms-full.txt, and this page is available as Markdown at https://yichenzhu1337.github.io/rspack-plugin-svg-sprite/docs/migrating.md.

Migrating

From svg-sprite-loader

Swap the loader path and the plugin import. Your component code stays the same.

// rspack.config.js
-const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
+const { SvgSpritePlugin } = require('rspack-plugin-svg-sprite');

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
+       type: 'javascript/auto',
-       loader: 'svg-sprite-loader',
+       loader: 'rspack-plugin-svg-sprite/loader',
        options: {
          symbolId: 'icon-[name]',
+         // Add extract: true if you were using extract mode
        },
      },
    ],
  },
  plugins: [
-   new SpriteLoaderPlugin(),
+   new SvgSpritePlugin(), // Only needed for extract mode
  ],
};
Tip

The exported symbol object has the identical shape (id, viewBox, url, content), so no component changes are needed.

Three differences to check when you migrate:

  • Extract mode url target. svg-sprite-loader exports id: "arrow-usage" and url: "sprite.svg#arrow-usage", which point at a preview <use> element inside the sprite, so <img src={icon.url}> and CSS background: url(...) render the icon. This package exports id: "arrow" and url: "sprite.svg#arrow", which point at the <symbol>. That works with <svg><use href={icon.url} /></svg> (the recommended usage in both libraries), but browsers do not render a bare symbol as an image. If you used icon.url in an <img> or in CSS, switch to <svg><use href={icon.url} /></svg>.
  • class on the root <svg> is not copied to the <symbol>. The loader skips xmlns, version, class and style on the root element. svg-sprite-loader copies class. Put the class on the <svg> element where you use the icon.
  • Preview <use> elements in the sprite file use href, not xlink:href. href in <use> needs Safari 12.1 or newer. This only matters when you open the sprite file directly.

svg-sprite-loader depends on internal webpack APIs (NormalModule.getCompilationHooks, compilation.hooks.additionalAssets) that do not exist in Rspack (rspack#11609). This package reimplements the same functionality with Rspack-compatible APIs.

From asset/resource

If you handle SVGs with the built-in asset/resource type, replace it to get sprite support:

// rspack.config.js
+const { SvgSpritePlugin } = require('rspack-plugin-svg-sprite');

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
-       type: 'asset/resource',
-       generator: {
-         filename: 'images/icons/[name].[contenthash][ext]',
-       },
+       type: 'javascript/auto',
+       loader: 'rspack-plugin-svg-sprite/loader',
+       options: {
+         extract: true,
+         symbolId: '[name]',
+         spriteFilename: 'sprite.svg',
+       },
      },
    ],
  },
+ plugins: [
+   new SvgSpritePlugin({ plainSprite: true }),
+ ],
};
  • type: 'javascript/auto' is required. It overrides the previous asset/resource handling and lets the loader process SVGs as JavaScript modules.
  • The sprite file is emitted to your output directory (for example dist/sprite.svg).
  • If you generated sprites with a separate CLI tool (like svg-sprite) as a post-build step, you can remove it. The plugin does the work inside the build.

Alternatives

Featurerspack-plugin-svg-spritesvg-sprite-loader@svgr/webpack@rsbuild/plugin-svgrvite-plugin-svg-icons
Rspack supportNativeNo (uses webpack internals)Via configRsbuild onlyNo (Vite only)
ApproachSVG sprites (<use>)SVG sprites (<use>)React componentsReact componentsSVG sprites
Inline modeYesYesN/AN/AYes
Extract modeYesYesN/AN/ANo
Webpack 5 supportYesYesYesNoNo
Runtime depsZero1SeveralSeveralSeveral
MaintainedYesNo (archived)YesYesYes
Drop-in migrationn/aYes (same API)Different APIDifferent APIDifferent API

Use SVG sprites when you want icons combined into one file with <use href="#id"> references: good for large icon sets, full CSS control and caching. Use SVGR when you want each SVG as a React component with props for color and size.