Skip to content

Commit cac4938

Browse files
committed
play with iconfont to make it work
1 parent 92916b8 commit cac4938

1 file changed

Lines changed: 25 additions & 28 deletions

File tree

gulpfile.mjs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,48 +98,45 @@ gulp.task('Iconfont', async () => {
9898
);
9999
}
100100

101-
// Create a fresh, plain options object to ensure it's mutable and not frozen
102-
// This is important because some environments might freeze objects
103-
const iconfontOptions = Object.assign({}, {
104-
fontName: 'iconFont', // Required by svgicons2svgfont - must be first
105-
prependUnicode: true,
106-
formats: ['ttf', 'eot', 'woff', 'svg'],
107-
normalize: true,
108-
fontWeight: '300',
109-
fontHeight: 100,
110-
fixedWidth: false,
111-
centerHorizontally: false,
112-
});
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+
const iconfontOptions = {};
104+
iconfontOptions.fontName = 'iconFont'; // MUST be set first - required by svgicons2svgfont
105+
iconfontOptions.prependUnicode = true;
106+
iconfontOptions.formats = ['ttf', 'eot', 'woff', 'svg'];
107+
iconfontOptions.normalize = true;
108+
iconfontOptions.fontWeight = '300';
109+
iconfontOptions.fontHeight = 100;
110+
iconfontOptions.fixedWidth = false;
111+
iconfontOptions.centerHorizontally = false;
113112

114-
// Ensure fontName is a non-empty string
113+
// Validate fontName before calling
115114
if (!iconfontOptions.fontName || typeof iconfontOptions.fontName !== 'string' || iconfontOptions.fontName.length === 0) {
116115
throw new Error(`fontName must be a non-empty string, got: ${JSON.stringify(iconfontOptions.fontName)}`);
117116
}
118117

119-
// Verify the options object is mutable (not frozen/sealed)
120-
try {
121-
iconfontOptions._test = true;
122-
delete iconfontOptions._test;
123-
} catch (e) {
124-
// If object is frozen, create a new one
125-
const newOpts = {};
126-
for (const key in iconfontOptions) {
127-
newOpts[key] = iconfontOptions[key];
128-
}
129-
Object.assign(iconfontOptions, newOpts);
130-
}
131-
132118
// Debug logging for CI
133119
if (process.env.CI) {
134120
console.log('[DEBUG] Iconfont options keys:', Object.keys(iconfontOptions));
135121
console.log('[DEBUG] fontName value:', iconfontOptions.fontName);
136122
console.log('[DEBUG] fontName type:', typeof iconfontOptions.fontName);
123+
console.log('[DEBUG] Options object:', JSON.stringify(iconfontOptions));
124+
console.log('[DEBUG] Function type:', typeof iconfontFn);
125+
console.log('[DEBUG] Function name:', iconfontFn.name || 'anonymous');
126+
}
127+
128+
// Call the function - ensure options object is passed correctly
129+
// The issue might be that gulp-iconfont does: options = options || {}
130+
// So we need to ensure options is truthy and has all required properties
131+
const stream = iconfontFn(iconfontOptions);
132+
133+
if (!stream) {
134+
throw new Error('gulp-iconfont did not return a stream');
137135
}
138136

139-
// Call the function directly - ensure options are passed as a plain object
140137
return gulp
141138
.src(['assets/img/icons/*.svg'])
142-
.pipe(iconfontFn(iconfontOptions))
139+
.pipe(stream)
143140
.pipe(gulp.dest('build/assets/fonts/'));
144141
});
145142

0 commit comments

Comments
 (0)