
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
vite-plugin-react-svg
Advanced tools
Extend Vite with ability to use SVG files as React components.
?url
and ?component
query string2.0.0-beta.61
yarn add --dev vite-plugin-react-svg
npm i -D vite-plugin-react-svg
// vite.config.js
const reactRefresh = require('@vitejs/plugin-react-refresh');
const reactSvgPlugin = require('vite-plugin-react-svg');
module.exports = {
plugins: [
reactRefresh(),
reactSvgPlugin(),
],
};
reactSvgPlugin({
// Default behavior when importing `.svg` files, possible options are: 'url' and `component`
defaultExport: 'url',
// Boolean flag to enable/disable SVGO
svgo: true,
// SVGO configuration object
svgoConfig: {},
// Props to be forwarded on SVG tag, ossible options: "start", "end" or false
expandProps: 'end',
// Setting this to true will forward ref to the root SVG tag
ref: false,
// Setting this to true will wrap the exported component in React.memo
memo: false,
// Replace an attribute value by an other.
// The main usage of this option is to change an icon color to "currentColor" in order to inherit from text color.
// replaceAttrValues: { old: 'new' },
replaceAttrValues: null,
// Add props to the root SVG tag
// svgProps: { name: 'value' },
svgProps: null,
// Add title tag via title property
// <SvgIcon title="Accessible icon name" /> => <svg><title>Accessible icon name</title><...></svg>
// <SvgIcon title="Accessible icon name" titleId="iconName" /> => <svg aria-labelledby="iconName><title id="iconName">Accessible icon name</title><...></svg>
titleProp: false,
})
import MyIcon from './svgs/my-icon.svg?component';
function App() {
return (
<div>
<MyIcon />
</div>
);
}
FAQs
Import SVG files as React Components
The npm package vite-plugin-react-svg receives a total of 3,293 weekly downloads. As such, vite-plugin-react-svg popularity was classified as popular.
We found that vite-plugin-react-svg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.