npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rspack-plugin-solid-svg

v1.2.0

Published

Transform SVG files into SolidJS components for Rspack and Rsbuild (with Webpack support).

Readme

rspack-plugin-solid-svg

CI npm version License: MIT Node

Webpack/Rspack/Rsbuild plugin for transforming SVG files into SolidJS components.

Overview

This plugin allows you to import SVG files to SolidJS components in your webpack/rspack/rsbuild projects. It works in two modes:

  • SVG files added with .svg?solid are transformed into SolidJS components. By default, they are optimized with SVGO.
  • SVG files added with .svg are imported as URLs (Rspack/Webpack) or use default handling (Rsbuild).

Installation

npm install -D rspack-plugin-solid-svg
# or
pnpm add -D rspack-plugin-solid-svg
# or
yarn add -D rspack-plugin-solid-svg

Usage

Basic Setup

For Rsbuild

// rsbuild.config.js
import { defineConfig } from '@rsbuild/core';
import { rsbuildPluginSolidSvg } from 'rspack-plugin-solid-svg/rsbuild';
// or: import { rsbuildPluginSolidSvg } from 'rspack-plugin-solid-svg';

export default defineConfig({
  plugins: [
    rsbuildPluginSolidSvg()
  ]
});

For Rspack/Webpack

// rspack.config.js or webpack.config.js
import { RspackPluginSolidSvg } from 'rspack-plugin-solid-svg/rspack';
// or: import { RspackPluginSolidSvg } from 'rspack-plugin-solid-svg';

export default {
  plugins: [
    new RspackPluginSolidSvg()
  ]
};

or using CommonJS syntax:

// rspack.config.js or webpack.config.js
const { RspackPluginSolidSvg } = require('rspack-plugin-solid-svg/rspack');
// or: const { RspackPluginSolidSvg } = require('rspack-plugin-solid-svg');

module.exports = {
  plugins: [
    new RspackPluginSolidSvg()
  ]
};

Importing SVGs

As SolidJS Component

import Icon from './icon.svg?solid';

function App() {
  return (
    <div>
      <Icon width={24} height={24} fill="red" />
    </div>
  );
}

As Asset URL

import iconUrl from './icon.svg';

function App() {
  return (
    <div>
      <img src={iconUrl} alt="Icon" />
    </div>
  );
}

Configuration

Rspack/Webpack

new RspackPluginSolidSvg({
  svgo: {
    enabled: true,
    svgoConfig: {
      // Default SVGO configuration
    }
  }
})

Custom SVGO Configuration

new RspackPluginSolidSvg({
  svgo: {
    enabled: true,
    svgoConfig: {
      plugins: [
        'removeMetadata',
        'removeTitle',
        'removeDesc',
        {
          name: 'removeAttrs',
          params: {
            attrs: '(data-name|data-id)'
          }
        },
        {
          name: 'addAttributesToSVGElement',
          params: {
            attributes: [
              { 'fill': 'currentColor' }
            ]
          }
        }
      ]
    }
  }
})

Disable SVGO

new RspackPluginSolidSvg({
  svgo: {
    enabled: false
  }
})

Rsbuild

// rsbuild.config.js
import { defineConfig } from '@rsbuild/core';
import { rsbuildPluginSolidSvg } from 'rspack-plugin-solid-svg/rsbuild';

export default defineConfig({
  plugins: [
    rsbuildPluginSolidSvg({
      svgo: {
        enabled: true,
        svgoConfig: {
          plugins: ['removeMetadata', 'removeTitle']
        }
      }
    })
  ]
});

Plugin Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | svgo.enabled | boolean | true | Enable/disable SVGO optimization | | svgo.svgoConfig | object | {} | SVGO configuration object |

Generated Component

The plugin generates SolidJS components with the following signature:

export default (props = {}) => (
  <svg {...props}>
    {/* SVG content here */}
  </svg>
);

Props

All props are spread onto the SVG element, allowing you to:

  • Set dimensions: width, height
  • Add styling: fill, stroke, class
  • Add event handlers: onClick, onMouseOver
  • Add accessibility: aria-label, role

Example

import Star from './star.svg?solid';

function Rating({ rating }) {
  return (
    <div>
      {[1, 2, 3, 4, 5].map((value) => (
        <Star
          key={value}
          width={20}
          height={20}
          fill={value <= rating ? 'gold' : 'gray'}
          class="star-icon"
          onClick={() => setRating(value)}
        />
      ))}
    </div>
  );
}

SVGO Integration

The plugin uses SVGO for SVG optimization. Common optimizations include:

  • Remove metadata and comments
  • Remove unused elements and attributes
  • Optimize paths and shapes
  • Minify SVG code
  • Convert colors to more efficient formats

Using loader directly

If you need to change the .svg resolution behavior, you can use the loader directly:

// webpack.config.js
import { RspackPluginSolidSvg } from 'rspack-plugin-solid-svg';

export default {
  // Other settings
  // ...
  rules: [
    // Other rules
    // ...
    {
      test: /\.svg$/,
      resourceQuery: /\?solid/,
      use: [
        {
          loader: 'babel-loader',
          options: {
            presets: ['solid'],
          },
        },
        RspackPluginSolidSvg.loader,
      ],
      type: 'javascript/auto',
    },
    {
      test: /\.svg$/,
      resourceQuery: { not: [/\?solid/] },
      type: 'asset/resource',
    },
  ]
};

In Rsbuild it can be reached by modifying the Rspack config:

// rsbuild.config.js
import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginSolid } from '@rsbuild/plugin-solid';

import { RspackPluginSolidSvg } from 'rspack-plugin-solid-svg';

export default defineConfig({
  server: {
    open: false,
  },
  plugins: [
    pluginBabel({
      include: /\.(?:jsx|tsx)$/,
      babelLoaderOptions: {
        presets: ['solid'],
      },
    }),
    pluginSolid(),
  ],
  tools: {
    rspack: {
      module: {
        rules: [
          {
            test: /\.svg$/,
            resourceQuery: /\?solid/,
            use: [
              {
                loader: 'babel-loader',
                options: {
                  presets: ['solid'],
                },
              },
              {
                loader: RspackPluginSolidSvg.loader,
                options: {
                  svgo: { enabled: false },
                },
              },
            ],
            type: 'javascript/auto',
          },
          {
            test: /\.svg$/,
            resourceQuery: { not: [/\?solid/] },
            type: 'asset/resource',
            generator: {
              filename: 'assets/[name].[hash][ext]',
            },
          },
        ],
      },
    },
  },
});

TypeScript Support

For TypeScript, you need to add the following declarations:

declare module '*.svg?solid' {
  import type { Component, ComponentProps } from 'solid-js';
  const c: Component<ComponentProps<'svg'>>;
  export default c;
}

declare module '*.svg' {
  const content: string;
  export default content;
}

License

MIT License - see LICENSE for details.