Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@svgr/rollup
Advanced tools
@svgr/rollup is a Rollup plugin that transforms SVG files into React components. It allows you to import SVG files directly into your React components, making it easier to manage and use SVGs in your projects.
Transform SVG to React Component
This feature allows you to transform SVG files into React components using the @svgr/rollup plugin in your Rollup configuration. The code sample demonstrates how to set up the plugin in a Rollup configuration file.
import { defineConfig } from 'rollup';
import svgr from '@svgr/rollup';
export default defineConfig({
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
svgr()
]
});
Custom SVGR Options
This feature allows you to customize the SVGR options when transforming SVG files. The code sample shows how to enable the 'icon' option and configure SVGO to preserve the viewBox attribute.
import { defineConfig } from 'rollup';
import svgr from '@svgr/rollup';
export default defineConfig({
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
svgr({
icon: true,
svgoConfig: {
plugins: [{ removeViewBox: false }]
}
})
]
});
rollup-plugin-image is a Rollup plugin that allows you to import image files (including SVGs) as data URIs. Unlike @svgr/rollup, it does not transform SVGs into React components but instead provides a way to include images directly in your bundle.
rollup-plugin-svg is a Rollup plugin that imports SVG files as strings. This plugin is useful if you want to manipulate SVG content as a string or use it in a different way than transforming it into a React component, which is the primary functionality of @svgr/rollup.
vite-plugin-svgr is a Vite plugin that transforms SVGs into React components, similar to @svgr/rollup. It is specifically designed for use with Vite, a build tool that aims to provide a faster and leaner development experience for modern web projects.
Rollup plugin for SVGR.
npm install @svgr/rollup --save-dev
In your rollup.config.js
:
{
plugins: [svgr()]
}
In your code:
import Star from './star.svg'
const App = () => (
<div>
<Star />
</div>
)
{
plugins: [svgr({ native: true })]
}
url
pluginIt is possible to use it with url
.
In your rollup.config.js
:
{
plugins: [url(), svgr()]
}
In your code:
import starUrl, { ReactComponent as Star } from './star.svg'
const App = () => (
<div>
<img src={starUrl} alt="star" />
<Star />
</div>
)
The named export defaults to ReactComponent
, but can be customized with the namedExport
option.
By default, @svgr/rollup
applies a babel transformation with optimized configuration. In some case you may want to apply a custom one (if you are using Preact for an example). You can turn off Babel transformation by specifying babel: false
in options.
{
plugins: [svgr({ babel: false })]
}
MIT
FAQs
SVGR Rollup plugin.
We found that @svgr/rollup 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.