11import { transform } from '@svgr/core' ;
2+ import { optimize } from 'svgo' ;
23import _rawIcons from 'lucide-static' ;
34import fs from 'fs/promises' ;
45import path from 'path' ;
@@ -34,14 +35,25 @@ async function writeIcons() {
3435 await Promise . all (
3536 icons . map ( async icon => {
3637 const name = icon . name [ 0 ] . toLowerCase ( ) + icon . name . slice ( 1 ) ;
37- let code = await transform (
38- icon . data ,
39- {
40- icon : true ,
41- typescript : true ,
42- expandProps : false ,
43- template : function ( variables , context ) {
44- return context . tpl `
38+ const optimized = optimize ( icon . data , {
39+ plugins : [
40+ { name : 'preset-default' } ,
41+ {
42+ name : 'removeAttrs' ,
43+ params : { attrs : [ 'class' ] } ,
44+ } ,
45+ ] ,
46+ } ) . data ;
47+ let code = (
48+ await transform (
49+ optimized ,
50+ {
51+ icon : true ,
52+ typescript : true ,
53+ expandProps : false ,
54+ template : function ( variables , context ) {
55+ return context . tpl `
56+ /** LOCATION_FOR_REPLACEMENT */
4557 export const ${ name } = ${
4658 variables . jsx . children . length === 1
4759 ? variables . jsx . children [ 0 ]
@@ -57,14 +69,22 @@ async function writeIcons() {
5769 }
5870 }
5971 ` ;
72+ } ,
73+ plugins : [ '@svgr/plugin-jsx' , '@svgr/plugin-prettier' ] ,
6074 } ,
61- plugins : [
62- '@svgr/plugin-svgo' ,
63- '@svgr/plugin-jsx' ,
64- '@svgr/plugin-prettier' ,
65- ] ,
66- } ,
67- { componentName : name }
75+ { componentName : name }
76+ )
77+ ) . replace (
78+ 'LOCATION_FOR_REPLACEMENT' ,
79+ `
85+ . replace ( / c u r r e n t C o l o r / g, '#000' ) ,
86+ 'utf8'
87+ ) . toString ( 'base64' ) } )`
6888 ) ;
6989 await fs . writeFile ( path . join ( iconOutDir , `${ name } .tsx` ) , code ) ;
7090 } )
0 commit comments