@@ -84,73 +84,47 @@ gulp.task('Iconfont', async () => {
8484 const iconfontModule = await import ( 'gulp-iconfont' ) ;
8585
8686 // Extract the function - CommonJS modules use .default when imported via dynamic import()
87- let iconfontFn = iconfontModule . default ;
88- if ( typeof iconfontFn !== 'function' ) {
89- iconfontFn = iconfontModule ;
90- }
87+ const iconfontFn = iconfontModule . default ?? iconfontModule ;
88+
9189 if ( typeof iconfontFn !== 'function' ) {
9290 throw new Error (
9391 `gulp-iconfont is not a function. ` +
9492 `Got: ${ typeof iconfontFn } , ` +
9593 `default: ${ typeof iconfontModule . default } , ` +
96- `module: ${ typeof iconfontModule } , ` +
97- `keys: ${ Object . keys ( iconfontModule ) . join ( ', ' ) } `
94+ `module: ${ typeof iconfontModule } `
9895 ) ;
9996 }
10097
101- // Create options object - ensure fontName is explicitly set and not lost
102- // gulp-iconfont passes options directly to svgicons2svgfont, so fontName must be present
103- // IMPORTANT: Create options as a plain object with fontName as an enumerable property
104- // The issue might be that when gulp-iconfont does "options = options || {}", if options
105- // is somehow falsy, it creates a new empty object, losing fontName
98+ const runTimestamp = Math . round ( Date . now ( ) / 1000 ) ;
99+
106100 const iconfontOptions = {
107- fontName : 'iconFont' , // MUST be present - required by svgicons2svgfont
101+ fontName : 'iconFont' , // required by svgicons2svgfont
108102 prependUnicode : true ,
109103 formats : [ 'ttf' , 'eot' , 'woff' , 'svg' ] ,
110104 normalize : true ,
111105 fontWeight : '300' ,
112106 fontHeight : 100 ,
113107 fixedWidth : false ,
114108 centerHorizontally : false ,
109+ timestamp : runTimestamp , // recommended for consistent builds
115110 } ;
116111
117- // Ensure fontName is a non-empty string and is enumerable
118- if ( ! iconfontOptions . fontName || typeof iconfontOptions . fontName !== 'string' || iconfontOptions . fontName . length === 0 ) {
119- throw new Error ( `fontName must be a non-empty string, got: ${ JSON . stringify ( iconfontOptions . fontName ) } ` ) ;
120- }
112+ // Check function arity to determine API version
113+ // v11.0.1 and earlier: function(options) - transform plugin
114+ // v11.0.2+: function(glob, options) - direct call
115+ const functionArity = iconfontFn . length ;
121116
122- // Verify fontName is enumerable (can be seen by Object.keys)
123- const keys = Object . keys ( iconfontOptions ) ;
124- if ( ! keys . includes ( 'fontName' ) ) {
125- throw new Error ( 'fontName is not enumerable in options object' ) ;
117+ if ( functionArity === 2 ) {
118+ // New API: iconfont(glob, options) -> returns stream
119+ return iconfontFn ( 'assets/img/icons/*.svg' , iconfontOptions )
120+ . pipe ( gulp . dest ( 'build/assets/fonts/' ) ) ;
121+ } else {
122+ // Old API: .pipe(iconfont(options)) - transform plugin
123+ return gulp
124+ . src ( [ 'assets/img/icons/*.svg' ] )
125+ . pipe ( iconfontFn ( iconfontOptions ) )
126+ . pipe ( gulp . dest ( 'build/assets/fonts/' ) ) ;
126127 }
127-
128- // Debug logging for CI
129- if ( process . env . CI ) {
130- console . log ( '[DEBUG] Iconfont options keys:' , keys ) ;
131- console . log ( '[DEBUG] fontName value:' , iconfontOptions . fontName ) ;
132- console . log ( '[DEBUG] fontName type:' , typeof iconfontOptions . fontName ) ;
133- console . log ( '[DEBUG] fontName in options:' , 'fontName' in iconfontOptions ) ;
134- console . log ( '[DEBUG] Options object:' , JSON . stringify ( iconfontOptions ) ) ;
135- console . log ( '[DEBUG] Function type:' , typeof iconfontFn ) ;
136- console . log ( '[DEBUG] Function name:' , iconfontFn . name || 'anonymous' ) ;
137-
138- // Test if the function can see fontName
139- try {
140- const testOpts = { fontName : 'test' } ;
141- const testStream = iconfontFn ( testOpts ) ;
142- console . log ( '[DEBUG] Test call succeeded, stream type:' , typeof testStream ) ;
143- } catch ( e ) {
144- console . log ( '[DEBUG] Test call failed:' , e . message ) ;
145- }
146- }
147-
148- // Call the function - pass options directly
149- // gulp-iconfont will pass these options to svgicons2svgfont
150- return gulp
151- . src ( [ 'assets/img/icons/*.svg' ] )
152- . pipe ( iconfontFn ( iconfontOptions ) )
153- . pipe ( gulp . dest ( 'build/assets/fonts/' ) ) ;
154128} ) ;
155129
156130gulp . task ( 'images' , ( ) => {
0 commit comments