@@ -80,21 +80,40 @@ gulp.task('fonts', () => {
8080
8181// Iconfont
8282gulp . task ( 'Iconfont' , async ( ) => {
83- const iconfont = ( await import ( 'gulp-iconfont' ) ) . default ;
83+ const iconfontModule = await import ( 'gulp-iconfont' ) ;
84+ // Handle both ESM default export and CommonJS module.exports
85+ // CommonJS modules imported via dynamic import() have their exports as .default
86+ let iconfont = iconfontModule . default ;
87+ if ( ! iconfont || typeof iconfont !== 'function' ) {
88+ iconfont = iconfontModule ;
89+ }
90+ if ( typeof iconfont !== 'function' ) {
91+ throw new Error ( `gulp-iconfont export is not a function. Got: ${ typeof iconfont } , keys: ${ Object . keys ( iconfontModule ) . join ( ', ' ) } ` ) ;
92+ }
93+
94+ // Create options object with required fontName
95+ const options = Object . assign ( { } , {
96+ fontName : 'iconFont' ,
97+ prependUnicode : true ,
98+ formats : [ 'ttf' , 'eot' , 'woff' , 'svg' ] ,
99+ normalize : true ,
100+ fontWeight : '300' ,
101+ fontHeight : 100 ,
102+ fixedWidth : false ,
103+ centerHorizontally : false ,
104+ } ) ;
105+
106+ // Double-check fontName is present before calling
107+ if ( ! options . fontName ) {
108+ throw new Error ( 'fontName option is required but missing' ) ;
109+ }
110+
111+ // Call the function with options
112+ const iconfontStream = iconfont ( options ) ;
113+
84114 return gulp
85115 . src ( [ 'assets/img/icons/*.svg' ] )
86- . pipe (
87- iconfont ( {
88- fontName : 'iconFont' ,
89- prependUnicode : true ,
90- formats : [ 'ttf' , 'eot' , 'woff' , 'svg' ] ,
91- normalize : true ,
92- fontWeight : '300' ,
93- fontHeight : 100 ,
94- fixedWidth : false ,
95- centerHorizontally : false ,
96- } ) ,
97- )
116+ . pipe ( iconfontStream )
98117 . pipe ( gulp . dest ( 'build/assets/fonts/' ) ) ;
99118} ) ;
100119
0 commit comments