Supercharge Your SVG Sprite Icons Library with This GitHub Template
Tags: npm, github, react, javascript
Published: 2023-09-18 18:34:57

Hello, awesome developers and designers! 🚀

Ever grappled with the challenges of managing, generating, or publishing your SVG icons as sprites? I've got a gem for you. Introducing a GitHub repository designed for generating and publishing SVG icons. It's a fantastic tool that can automate your icon workflow, and the best part? You can use it as a template for your own projects!

## 🌟 Features:

- **SVG Sprite Generation:** Automatically generate an SVG sprite from individual SVG icons.
- **Documentation:** Auto-generates documentation for the SVG sprite.
- **NPM Publishing:** With every push to master, the package is updated with a new version on npm.
- **GitHub Actions Automation:** Everything from generation to publishing is automated!
- **Use your npm library:** After publishing, the generated npm module can be easily imported and used in any of your other projects, ensuring consistent iconography across all your applications.

![Use your npm library](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34r4araa0xjad1ydwnqa.gif)

## 🧠 Under the Hood: react-svg-sprite-generator

Now, the real magic behind this is the module [react-svg-sprite-generator](https://www.npmjs.com/package/react-svg-sprite-generator). If you're curious about diving deeper into its functionalities, check out my [detailed article](https://dev.to/simprl/streamline-svg-sprites-in-your-react-applications-37c) where I've explored its capabilities extensively.

## 🛠️ How It Works:

- **Push to Master:** Upon pushing to the master branch, the magic begins.
![github actions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5j1dxe1dglhx0g7pjob.png)

- **SVG Generation & Documentation:** The SVG sprite is generated along with associated documentation.
![SVG Generation & Documentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vzp1mk4w78npypa1ayq.png)

- **NPM Versioning & Publishing:** The module version is bumped, and then it’s published to npm with the new version.
![NPM Versioning & Publishing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2o96m3mn3m3rtnckwjrj.png)

- **Dynamic README.md:** The repository README is crafted from a template, followed by a table of the SVG icons generated.
![Dynamic README.md](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve9uzx9h403bpb6awch0.png)

## 🚀 Getting Started:

This repository is designed not only for immediate use but can also be used as a template for your projects. Here's how:

Using the Repository as a Template:

1. Visit the [simprl/svg-icons-sprite-example](https://github.com/simprl/svg-icons-sprite-example) repository. ![svg-icons-sprite-example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znw75wuueo2bmbv5bnfy.png)


2. Click on "Use this template" to start a new repository based on this structure.

3. Modify as required, push your SVG icons, and watch the magic happen!

Some Customizations You Might Consider:

- Update the readme.template.md with project-specific details.
![readme.template.md](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2hugrnm6jfpn8ig1rat.png)

- Add your SVG icons in the src/assets/icons directory.
![Add your SVG icons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0spbchaws0l6vl1lw8z.png)

- Adjust GitHub Actions workflows if you have specific nuances in mind.
![GitHub Actions workflows](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtrvesr0xuvl3fxo16fg.png)

- Setup NPM_TOKEN if you're looking to publish to npm.
![Setup NPM_TOKEN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e1f37c362ym73thwpwc6.png)

## 💡 Why Use This?
Managing SVG icons can be daunting. With design changes, icon additions, or removals, managing these manually can be error-prone. With this setup:

- **Consistency:** Maintain a uniform set of icons.
- **Efficiency:** Streamline the icon update process.
- **Automation:** Reduce manual errors and increase productivity.
- **Collaboration:** Designers can push new icons, and the system takes care of the rest!

## 🤝 Contribution:

Open-source thrives with collaboration. Found a way to enhance this setup? Pull requests are welcome! Let's make this the go-to solution for SVG icon management.

## 📣 Conclusion:

Icons play a pivotal role in UI/UX design. With this SVG Icons Sprite Generator & Publisher repository, you're not just managing icons; you're crafting an experience. Give it a spin and let the automation simplify your workflow.

Feel free to ask questions, share your experiences, or suggest improvements in the comments below. Let's revolutionize the way we handle SVG icons together! 🌍🌟
[Link to the repository](https://github.com/simprl/svg-icons-sprite-example)