icon2component
v1.2.0
Published
A simple cli for converting svg icons to react components
Downloads
314
Maintainers
Readme
icon2component
A command-line helper for turning raw SVG files into reusable icon components (or Mui compatible components). It wraps the icon2component binary, handling formatting, attribute normalization, and SVGO optimizations so your icons are ready to drop into React projects—whether you prefer plain React components or Material UI wrappers.
Installation
- Local project (dev dependency):
yarn add @weblite/icon-cli --dev - Global tool:
yarn global add @weblite/icon-cli
The package exposes the icon2component executable once installed.
Getting Started
Add a script to your project
Add the following script to your
package.json:{ "scripts": { "generate-icons": "node ./dist/src/index.js make --keep-colors --camel-case-attrs --out-dir icons -- svgs" } }Organize your SVG files
Create a folder (
svgs/) in your project root and place all your SVG files there.Generate icon components
Run the script to convert your SVG files into icon components:
yarn generate-iconsThis will create the icon components in the
icons/folder (or the folder specified by--out-dir).
Usage
Run the CLI from the root of a project that contains an svgs/ directory with your source assets:
icon2component make \
--keep-colors \
--camel-case-attrs \
--out-dir icons \
-- svgsCommon flags
--keep-colorspreserves fill and stroke definitions from the source SVG.--camel-case-attrsconverts attributes likefill-ruletofillRulefor React.--template muiswitches to the bundled Material UI wrapper template. Omit the flag to emit plain React components.--out-dir <path>controls the folder where generated components are written (defaults toicons).--helpshows the full command reference.
All flags map directly to the underlying yargs command configuration, so you can combine them as needed.
Project Scripts
yarn build– compile TypeScript intodist/.yarn make– run the CLI locally using the current build output.yarn pub– publish to the configured npm registry (runsbuildfirst).
Development
- Install dependencies:
yarn install. - Make changes under
src/. - Run
yarn buildto regenerate the distribution files. - Test the CLI locally:
node dist/src/index.js make --help.
The repo ignores
dist/andexec/until you build locally. Publishing requires both directories to exist.
License
ISC © Mohammad Farvardin
