
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
@neodx/svg
Advanced tools
Supercharge your icons ⚡️
We're working on the new documentation, please, visit neodx.pages.dev to see the latest version.
vite
, webpack
, rollup
, esbuild
, etc.# npm
npm install -D @neodx/svg
# yarn
yarn add -D @neodx/svg
# pnpm
pnpm add -D @neodx/svg
We're highly recommended to start with our "Getting started" guide.
For better understanding and to access the latest version, please visit our documentation.
Our plugins are built upon unplugin and provide a consistent interface and working principle across all multiple bundlers and frameworks.
For instance, here's an example of vite
plugin with some options:
import svg from '@neodx/svg/vite';
export default defineConfig({
plugins: [
svg({
root: 'assets',
output: 'public'
})
]
});
It will search for all SVG files in assets
folder, group them by folders, optimize them with svgo
,
reset all colors to currentColor
and generate sprites in public
folder.
For more details, see our Step-by-step guide.
Automate your icons and forget about colors management issues.
When we're working with SVG icons, we always need to control icon colors from our CSS.
Well-known approach is to use currentColor
inside SVG and set color
property in CSS.
However, usually, we have different issues with this approach, for example:
To solve these issues, we're providing a powerful color reset mechanism (resetColors
option, enabled by default):
resetColors: false
)Check out our documentation for more details.
Note: If you used
definitions
orexperimentalRuntime
options before, you need to update your configuration, see Migration guide.
By default, you will get the following sprites in your output:
public/
+ sprite-foo.svg
+ sprite-bar.svg
But this is not very good for caching, because if you change any of the SVG files, the sprite filename won't be updated, which could result in an infinite cache.
To solve this issue and achieve content-based hashes in filenames, you need to take three steps:
fileName
option with a hash
variable (e.g. fileName: "{name}.{hash:8}.svg"
)metadata
option to get additional information about the file path by sprite name during runtimeIcon
component (or whatever you use) to support the new runtime information// vite.config.ts
export default defineConfig({
plugins: [
svg({
root: 'assets',
output: 'public/sprites',
fileName: '{name}.{hash:8}.svg',
metadata: {
path: 'src/sprite.gen.ts',
runtime: {
// generate runtime metadata (path and other information) for each sprite
size: true, // will add `width` and `height` properties
viewBox: true // will add `viewBox` property
}
}
})
]
});
In the result, you will get the following sprites in your output:
/
├── assets
│ ├── common
│ │ ├── left.svg
│ │ └── right.svg
│ └── actions
│ └── close.svg
├── public
+ └── sprites
+ ├── common.12ghS6Uj.svg
+ └── actions.1A34ks78.svg
└── src
+ └── sprite.gen.ts
To learn how to use it, check out our "Writing an Icon component" guide or detailed basic tutorials:
It's a simplified tutorial, for detailed one check our "Getting started" guide.
Our example stack details:
vite
react
typescript
tailwindcss
We'll be working with the following icons in our project:
/
├── assets
│ ├── common
│ │ ├── left.svg
| | ... other icons
│ │ └── right.svg
│ └── actions
│ ... other icons
│ └── close.svg
We want to generate separate sprites for each folder and use them in our React components.
import { defineConfig } from 'vite';
import svg from '@neodx/svg/vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
plugins: [
react(),
tsconfigPaths(),
svg({
root: 'assets',
group: true,
output: 'public/sprites',
metadata: 'src/shared/ui/icon/sprite.gen.ts'
})
]
});
Now let's run vite
(or vite build
) and see what we have:
/
├── assets
│ ├── common
│ │ ├── left.svg
│ │ └── right.svg
│ └── actions
│ └── close.svg
├── public
+ └── sprites
+ ├── common.svg
+ └── actions.svg
└── src
└── shared
└── ui
└── icon
+ └── sprite.gen.ts
Now you could visit our "Writing an Icon component" guide to learn how to use it.
definitions
and experimentalRuntime
options to metadata API
Now metadata is stable
and covered under one metadata
option.
svg({
- definitions: 'src/shared/ui/icon/sprite.gen.ts',
- experimentalRuntime: true,
+ metadata: {
+ path: 'src/shared/ui/icon/sprite.gen.ts',
+ runtime: {
+ size: true,
+ viewBox: true,
+ }
+ }
});
FAQs
Supercharge your icons ⚡️
The npm package @neodx/svg receives a total of 1,222 weekly downloads. As such, @neodx/svg popularity was classified as popular.
We found that @neodx/svg demonstrated a healthy version release cadence and project activity because the last version was released less than 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
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.