
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
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 1,913 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
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.