File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import data from "@iconify-json/simple-icons/icons.json" with { type : "json" } ;
2+
3+ const ID = "virtual:iconify-simple-icons" ;
4+
5+ /**
6+ * Vite plugin to make iconify simple icons data is tree-shakeable
7+ * @param {Array<string> } icons Icons you want to include.
8+ */
9+ export function iconify ( icons ) {
10+ return /** @type {import("vite").Plugin } */ ( {
11+ name : "iconify" ,
12+ resolveId ( id ) {
13+ if ( id === ID ) {
14+ return ID ;
15+ }
16+ } ,
17+ load ( id ) {
18+ if ( id === ID ) {
19+ let code = "export default {\n" ;
20+
21+ for ( const icon of icons ) {
22+ if ( ! ( icon in data . icons ) ) {
23+ this . info ( `Icon \`${ icon } \` is not available.` ) ;
24+ continue ;
25+ }
26+ code += `"${ icon } ": ${ JSON . stringify ( data . icons [ icon ] . body ) } ,\n` ;
27+ }
28+
29+ code += "}\n" ;
30+ return code ;
31+ }
32+ } ,
33+ } ) ;
34+ }
Original file line number Diff line number Diff line change 11<script >
2- import { icons } from " @ iconify-json/ simple-icons/icons.json " ;
2+ import data from " virtual: iconify-simple-icons" ;
33 import { height } from " @iconify-json/simple-icons/info.json" ;
44
55 let { icon, class: classes, ... rest } = $props ();
6+
7+ const icons = new Proxy (data, {
8+ get (o , p ) {
9+ if (p in o) {
10+ return o[p];
11+ } else {
12+ throw new Error (` Icon \` ${ p} \` is not available.` );
13+ }
14+ },
15+ });
616 </script >
717
818<svg
1222 fill =" currentColor"
1323 viewBox ="0 0 {height } {height }"
1424 class ={classes }
15- {...rest }>{@html icons [icon ]?. body ?? " " }</svg >
25+ {...rest }>{@html icons [icon ] ?? " " }</svg >
Original file line number Diff line number Diff line change 11import { sveltekit } from "@sveltejs/kit/vite" ;
22import { defineConfig } from "vite" ;
33import tailwindcss from "@tailwindcss/vite" ;
4+ import { iconify } from "./scripts/iconify-plugin.js" ;
5+ import dataForHome from "./src/routes/data-for-home.json" with { type : "json" } ;
46
57export default defineConfig ( {
6- plugins : [ sveltekit ( ) , tailwindcss ( ) ] ,
8+ plugins : [
9+ sveltekit ( ) ,
10+ tailwindcss ( ) ,
11+ /* prettier-ignore */
12+ iconify ( [
13+ ...dataForHome . languages . map ( ( data ) => data . icon ) ,
14+ ...dataForHome . tools . map ( ( data ) => data . icon ) ,
15+ ...dataForHome . frameworkLibrary . map ( ( data ) => data . icon ) ,
16+ "bookstack" ,
17+ "github" ,
18+ "googlemaps"
19+ ] ) ,
20+ ] ,
721 json : {
822 namedExports : true ,
923 } ,
You can’t perform that action at this time.
0 commit comments