Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use svg sprite for icons #480

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

feat: use svg sprite for icons #480

wants to merge 30 commits into from

Conversation

G3root
Copy link
Collaborator

@G3root G3root commented Aug 10, 2024

Rendering icons as JSX components is expensive and significantly increases the size of your bundle. This PR aims to address that by replacing them with SVG sprite icons, which are cacheable and faster than the JS based solution.

here's a explanation why we shouldn't import SVG icons as JSX https://twitter.com/_developit/status/1382838799420514317?lang=en

advantages using sprite sheet icons

  • doesn't increase js bundle size
  • icons can be cacheable since it's a single svg
  • icons can be easily organized later by adding consistent sizing due to being a single component

Copy link

github-actions bot commented Aug 10, 2024

Thank you for following the naming conventions for pull request titles! 🙏

import { $ } from "execa";
import glob from "fast-glob";
import fsExtra from "fs-extra";
import { parse } from "node-html-parser";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script to generate sprite sheet

@@ -18,6 +18,7 @@
"db:seed": "NODE_ENV='test' tsx prisma/seeds/index.ts",
"dev": "next dev",
"build": "next build",
"build:icons": "tsx scripts/build-icons.ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command to rebuild the sprite sheet when new icons are added to the list

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is generated by npm run build:icons -->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generated sprite sheet

export const iconList = new Set([
"account-circle-fill",
"account-circle-line",
"add-circle-line",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list of icons we are using through out the app

import type { IconName } from "./icon-names";

import { cn } from "@/lib/utils";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

icon component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant