• Stars
    star
    229
  • Rank 174,666 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎐 Bundles icons on demand

It's now recommended to use UnoCSS Icons, unplugin-icons or Iconify Icon Components instead of this approach.


PurgeIcons

Bundles only the icons you use

Think about TailwindCSS + PurgeCSS, but for Icons.

GIF Demo

Intro

PurgeIcons is heavily inspired from PurgeCSS. It analyzes your source code or dist files, extracting the icon names you used, and then bundle the icons' data (SVGs) into your code.

You will only get icons you need. No extra bandwidth, no unused icons, no compromise.

Underneath, it's powered by Iconify, which you get access to 80+ popular open source iconsets with over 5,000 icons to choice, including Material Design Icons, Font Awesome, Octicon and even Emojis!

Browser the icon sets in IcΓ΄nes or Iconify.

Usage

Just like what you used to do for Iconify.

<span class="iconify" data-icon="fa:home"></span>

Or even dynamic

const span = createElement('span')
span.class = 'iconify'
span.data.icon = isDark ? 'carbon:moon' : 'carbon:sun'

// DON'T, PurgeIcons won't extract them correct.
// add them to `included` to be always bundled if you really want this
span.data.icon = `carbon:${isDark ? 'moon' : 'sun'}`

Install

PurgeIcons is designed to be framework independent, but using framework plugins is the most recommended way to get started. Check out the supported frameworks in the following list. We are trying to make more frameworks able to use PurgeIcons out-of-box. Pull requests are great welcome!

Official Plugins

Plugin Example Template
Vite vite-plugin-purge-icons Example Vitesse
Nuxt nuxt-plugin-purge-module Example
Vue CLI Coming...
Gridsome Coming...
Parcel Coming...
Webpack purge-icons-webpack-plugin
Rollup rollup-plugin-purge-icons

Command Line Interface

The CLI is still working in progress and the design is not yet finalized.

You can either install PurgeIcons as a dev dependency and use the CLI with npx or you can also install PurgeIcons globally:

npm i -g purge-icons

Scan the all the html file and geneted a mjs bundle

purge-icons --content 'src/*.html' --format mjs --output output.js

From multiple sources and use args shorthands, format can be auto inferred from the output option

purge-icons -c 'index.html,src/**/*.vue' -o output.ts

Or export plain json file for other tools to process

purge-icons -c index.html -o output.json

See more options by

purge-icons --help

Programmatic API

Programmatic API is still working in progress as well.

For programmatic use only, you can use @purge-icons/core

npm i -D @purge-icons/core
import { PurgeIconsOptions, PurgeIcons } from '@purge-icons/core'

const code = await PurgeIcons({
  // globs for searching source file to analyze
  content: [
    '**/*.html',
    '**/*.js',
    '**/*.vue', // scan for .vue file as well
  ],
  // whitelist for icons that might be used dynamically
  included: [
    'mdi:account-circle-outline', // from Material Design Icons
    'fa:camera', // from Font Awesome 4
  ],
  format: 'mjs'
})

// code is generated with inlined icons's data, bundle the file and it's done.
fs.promises.writeFiles('./icons.mjs', code, 'utf-8')

Options

export interface PurgeIconsOptions {
  content?: (string | RawContent)[]
  included?: string[]
  extractors?: Extractor[]
  iconSource?: IconSource // default to 'auto'
}

How It Works

Iconify is an icon framework that provide an unified syntax to use icons from its huge collections on-demanded. Each icon set has a id as the prefix of for its icons. For example:

<span class="iconify" data-icon="fa:home"></span>   <!-- Font Awesome -->
<span class="iconify" data-icon="noto:bird"></span> <!-- Note Icons -->
<span class="iconify" data-icon="mdi:alert"></span> <!-- Material Design Icons -->

Iconify achieve that by building up a API service that only send the icons you need. It provides a great flexibility that you can try with different design style and without to worry about including a large amount of unused icons that eat up your bandwidth and slow down your page load.

However, the downside of API querying is that the icons won't be available on the first meaningful paint and your app will be heavy relied on the API servers' status and so its accessability for your users. Iconify also provides the offline solution by implementing frameworks components. In that way, you would need to manually import every icon you use.

Thus, PurgeIcons was born. By scanning your code, it generates bundles for Iconify and load them synchronously. You can use icons in the exact same way as you would with the API based solution.

TODO

  • CLI output
  • Better caching
  • Plugins for frameworks (Vue CLI, Nuxt.js, Next.js, etc.) PR welcome!
  • Font-based icons (Javascript Free)

License

MIT License Β© 2020 Anthony Fu

More Repositories

1

vitesse

πŸ• Opinionated Vite + Vue Starter Template
TypeScript
8,522
star
2

ni

πŸ’‘ Use the right package manager
TypeScript
4,527
star
3

icones

⚑️ Icon Explorer with Instant searching, powered by Iconify
Vue
4,525
star
4

unplugin-vue-components

πŸ“² On-demand components auto importing for Vue
TypeScript
3,011
star
5

unocss

The instant on-demand atomic CSS engine.
TypeScript
2,990
star
6

unplugin-icons

🀹 Access thousands of icons as components on-demand universally.
TypeScript
2,793
star
7

vitesse-webext

⚑️ WebExtension Vite Starter Template
TypeScript
2,581
star
8

unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
TypeScript
2,307
star
9

vscode-file-nesting-config

Config of File Nesting for VS Code
JavaScript
2,132
star
10

vue-starport

πŸ›° Shared component across routes with animations
TypeScript
1,744
star
11

vscode-settings

My VS Code settings and extensions
1,739
star
12

eslint-config

Anthony's ESLint config presets
JavaScript
1,605
star
13

vitesse-nuxt3

Vitesse for Nuxt 3 πŸ”πŸ’šβš‘οΈ
TypeScript
1,510
star
14

shikiji

A syntax highlighter based on TextMate grammars. ESM rewrite of shiki, with more features and capabilities.
TypeScript
1,465
star
15

reactivue

πŸ™Š Use Vue Composition API in React components
TypeScript
1,415
star
16

taze

πŸ₯¦ A modern cli tool that keeps your deps fresh
TypeScript
1,233
star
17

vite-ssg

Static site generation for Vue 3 on Vite
TypeScript
1,198
star
18

handle

A Chinese Hanzi variation of Wordle - 汉字 Wordle
TypeScript
1,194
star
19

qrcode-toolkit

Anthony's QR Code Toolkit for AI generated QR Codes
Vue
1,111
star
20

case-police

🚨 Make the case correct, PLEASE!
TypeScript
1,098
star
21

vite-plugin-inspect

Inspect the intermediate state of Vite plugins
Vue
1,009
star
22

use

Things I am using
991
star
23

vitesse-lite

⛺️ Lightweight version of Vitesse
TypeScript
901
star
24

drauu

Headless SVG-based drawboard in browser.
TypeScript
817
star
25

broz

A simple, frameless browser for screenshots
JavaScript
745
star
26

iroiro

Beautiful Colors Lookup in CLI
TypeScript
735
star
27

retypewriter

Replay the steps of your changes at ease.
TypeScript
715
star
28

live-draw

A tool allows you to draw on screen real-time.
C#
706
star
29

sd-webui-qrcode-toolkit

Anthony's QR Toolkit for Stable Diffusion WebUI
JavaScript
640
star
30

changelogithub

Generate changelog for GitHub
TypeScript
613
star
31

vite-plugin-md

Markdown with Vue for Vite
TypeScript
602
star
32

vscode-smart-clicks

Smart selection with double clicks for VS Code.
TypeScript
601
star
33

unplugin-vue2-script-setup

πŸ’‘ Bring `<script setup>` to Vue 2.
TypeScript
567
star
34

sponsorkit

πŸ’– Toolkit for generating sponsors images πŸ˜„
TypeScript
550
star
35

eslint-flat-config-viewer

A visual tool to help you view and understand your ESLint Flat config.
Vue
549
star
36

unconfig

A universal solution for loading configurations.
TypeScript
524
star
37

utils

Collection of common JavaScript / TypeScript utils
TypeScript
493
star
38

100

My 100-day project of exploring design, compform, and new things.
Vue
491
star
39

v-lazy-show

Compile-time directive to lazy initialize v-show for Vue
TypeScript
487
star
40

antfu.me

My personal website
Markdown
463
star
41

raycast-multi-translate

A Raycast extension that translates text to multiple languages at once
TypeScript
454
star
42

vue-reuse-template

Define and reuse Vue template inside the component scope.
TypeScript
440
star
43

vite-node

Vite as Node.js runtime
JavaScript
428
star
44

vscode-browse-lite

πŸš€ An embedded browser in VS Code
TypeScript
425
star
45

vscode-vite

One step faster for Vite in VS Code ⚑️
TypeScript
404
star
46

vscode-theme-vitesse

πŸ• Vitesse theme for VS Code
TypeScript
395
star
47

starter-ts

Starter template for TypeScript library
TypeScript
386
star
48

vue-template-promise

Template as Promise in Vue
TypeScript
373
star
49

vue-global-api

Use Vue Composition API globally
TypeScript
331
star
50

vue-router-better-scroller

Enhanced scroll behavior for Vue Router
TypeScript
327
star
51

qr-scanner-wechat

QR Code scanner in JS with Open CV and WeChat's Algorithm
JavaScript
322
star
52

starter-vscode

Starter template for VS Code Extension
TypeScript
299
star
53

vscode-iconify

πŸ™‚ Iconify IntelliSense for VS Code
TypeScript
294
star
54

1990-script

Make your GitHub history back to 1990
Shell
293
star
55

p

Toolkit for managing multiple promises
TypeScript
284
star
56

wenyan-lang-vscode

文言 Wenyan Lang for VS Code
TypeScript
277
star
57

pnpm-patch-i

A better and interactive pnpm patch
TypeScript
265
star
58

fsxx

File system in zx style
JavaScript
262
star
59

birpc

Message-based two-way remote procedure call.
TypeScript
245
star
60

vue-minesweeper

A tiny minesweeper clone in Vue 3
TypeScript
242
star
61

contribute

Contribution guide for my projects
231
star
62

vscode-open-in-github-button

Add a button to go to the GitHub on the status bar.
TypeScript
224
star
63

github-doorcat

😼 Supercharges GitHub navbar for fast navigation [WIP]
TypeScript
214
star
64

vscode-goto-alias

Go to Definition following alias redirections.
TypeScript
211
star
65

refined-github-notifications

UserScript that enhances the GitHub Notifications
JavaScript
208
star
66

eslint-plugin-command

Comment-as-command for one-off codemod with ESLint.
TypeScript
195
star
67

nuxt-server-fn

Server functions in client for Nuxt 3
TypeScript
194
star
68

magic-string-stack

magic-string with the capability of committing changes.
TypeScript
190
star
69

vscode-array-index-inlay

Show array index inlay hints for large arrays for VS Code
TypeScript
185
star
70

eslint-typegen

Generate types from ESLint rule schemas, with auto-completion and type-checking for rule options.
TypeScript
185
star
71

prism-theme-vars

A customizable Prism.js theme using CSS variables
CSS
178
star
72

what-time

What time works for you?
Vue
177
star
73

esbuild-node-loader

Transpile TypeScript to ESM with Node.js loader.
JavaScript
175
star
74

userscript-clean-twitter

Bring back the peace on Twitter
JavaScript
174
star
75

vitesse-nuxt-bridge

πŸ• Vitesse experience for Nuxt 2 and Vue 2
Vue
174
star
76

vscode-icons-carbon

Carbon Visual Studio Code product icon theme
TypeScript
170
star
77

talks

Slides & code for my talks
Vue
170
star
78

fs-spy

Monitoring fs accessing for Node process
TypeScript
166
star
79

vite-plugin-glob

The design experiment for import.meta.glob from Vite.
TypeScript
164
star
80

diff-match-patch-es

ESM and TypeScript rewrite of Google's diff-match-patch for JavaScript
TypeScript
159
star
81

vite-plugin-optimize-persist

Persist dynamically analyzed dependencies optimization
TypeScript
155
star
82

eslint-ts-patch

Support loading eslint.config.mjs and eslint.config.ts as flat config files for ESLint.
JavaScript
155
star
83

markdown-it-github-alerts

Support GitHub-style alerts for markdown-it
TypeScript
153
star
84

regex-doctor

Monitor your RegExp consumption and provide suggestions to improve performance.
TypeScript
152
star
85

v-dollar

jQuery-like Vue Reactivity API
TypeScript
146
star
86

.github

The default community health files for all my repos on GitHub
146
star
87

p5i

p5.js, but with more friendly instance mode APIs
TypeScript
139
star
88

vscode-pnpm-catalog-lens

Show versions inline for PNPM catalog: field
TypeScript
136
star
89

magic-string-extra

Extended magic-string with extra utilities
TypeScript
131
star
90

export-size

Analysis bundle cost for each export of a package
TypeScript
130
star
91

eslint-plugin-format

Format various languages with formatters in ESLint
TypeScript
129
star
92

local-pkg

Get information on local packages.
TypeScript
126
star
93

vite-plugin-restart

Custom files/globs to restart Vite server
TypeScript
124
star
94

pkg-exports

Get exports of an local npm package.
TypeScript
118
star
95

qr-verify

A CLI to verify scannable QR Code in batch
TypeScript
114
star
96

eslint-plugin-antfu

Anthony extended ESLint rules.
TypeScript
114
star
97

install-pkg

Install package programmatically.
TypeScript
114
star
98

deploy-check

WIP, Prevent runtime errors earlier in CI
TypeScript
113
star
99

fast-npm-meta

A lightweight API server to get npm package metadata, resolve the latest versions on server, and batch multiple package resolutions in one request.
TypeScript
110
star
100

markdown-it-mdc

MDC (Markdown Components) syntax for markdown-it.
TypeScript
106
star