1
1
import { transform } from '@svgr/core' ;
2
+ import { optimize } from 'svgo' ;
2
3
import _rawIcons from 'lucide-static' ;
3
4
import fs from 'fs/promises' ;
4
5
import path from 'path' ;
@@ -34,14 +35,25 @@ async function writeIcons() {
34
35
await Promise . all (
35
36
icons . map ( async icon => {
36
37
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 */
45
57
export const ${ name } = ${
46
58
variables . jsx . children . length === 1
47
59
? variables . jsx . children [ 0 ]
@@ -57,14 +69,22 @@ async function writeIcons() {
57
69
}
58
70
}
59
71
` ;
72
+ } ,
73
+ plugins : [ '@svgr/plugin-jsx' , '@svgr/plugin-prettier' ] ,
60
74
} ,
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' ) } )`
68
88
) ;
69
89
await fs . writeFile ( path . join ( iconOutDir , `${ name } .tsx` ) , code ) ;
70
90
} )
0 commit comments