@@ -80,19 +80,26 @@ gulp.task('fonts', () => {
8080
8181// Iconfont
8282gulp . task ( 'Iconfont' , async ( ) => {
83+ // Dynamically import gulp-iconfont to avoid top-level await issues
8384 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 ( ', ' ) } ` ) ;
85+
86+ // Extract the function - CommonJS modules use .default when imported via dynamic import()
87+ // Try .default first, then fallback to the module itself
88+ const iconfontFn = ( typeof iconfontModule . default === 'function' )
89+ ? iconfontModule . default
90+ : ( typeof iconfontModule === 'function' ? iconfontModule : iconfontModule . default || iconfontModule ) ;
91+
92+ if ( typeof iconfontFn !== 'function' ) {
93+ throw new Error (
94+ `gulp-iconfont is not a function. ` +
95+ `Got: ${ typeof iconfontFn } , ` +
96+ `default: ${ typeof iconfontModule . default } , ` +
97+ `module: ${ typeof iconfontModule } `
98+ ) ;
9299 }
93100
94- // Create options object with required fontName
95- const options = Object . assign ( { } , {
101+ // Create options object - use plain object literal to ensure compatibility
102+ const iconfontOptions = {
96103 fontName : 'iconFont' ,
97104 prependUnicode : true ,
98105 formats : [ 'ttf' , 'eot' , 'woff' , 'svg' ] ,
@@ -101,19 +108,17 @@ gulp.task('Iconfont', async () => {
101108 fontHeight : 100 ,
102109 fixedWidth : false ,
103110 centerHorizontally : false ,
104- } ) ;
111+ } ;
105112
106- // Double-check fontName is present before calling
107- if ( ! options . fontName ) {
108- throw new Error ( ' fontName option is required but missing' ) ;
113+ // Double-check fontName exists and is a string
114+ if ( ! iconfontOptions . fontName || typeof iconfontOptions . fontName !== 'string' ) {
115+ throw new Error ( ` fontName is required but got: ${ iconfontOptions . fontName } ( ${ typeof iconfontOptions . fontName } )` ) ;
109116 }
110117
111- // Call the function with options
112- const iconfontStream = iconfont ( options ) ;
113-
118+ // Call the function directly with options
114119 return gulp
115120 . src ( [ 'assets/img/icons/*.svg' ] )
116- . pipe ( iconfontStream )
121+ . pipe ( iconfontFn ( iconfontOptions ) )
117122 . pipe ( gulp . dest ( 'build/assets/fonts/' ) ) ;
118123} ) ;
119124
0 commit comments