
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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 4,154 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.