مولد الخطوط من أيقونات SVG.
WOFF2 ، WOFF ، EOT ، TTF و SVG ؛JavaScript أو JSON أو YAML لتحديد معلومات التكوين لدليل كامل وجميع الدلائل الفرعية ؛css ، scss ، styl إلخ) ؛gulp أو grunt أو أدوات كبيرة أخرى ؛linux و windows و osx ) ؛npm install --save-dev webfont import webfont from "webfont" ;
webfont ( {
files : "src/svg-icons/**/*.svg" ,
fontName : "my-font-name" ,
} )
. then ( ( result ) => {
// Do something with result
Function . prototype ( result ) ;
// Or return it
return result ;
} )
. catch ( ( error ) => {
throw error ;
} ) ;أو
const webfont = require ( "webfont" ) . default ;
webfont ( {
files : "src/svg-icons/**/*.svg" ,
fontName : "my-font-name" ,
} )
. then ( ( result ) => {
// Do something with result
Function . prototype ( result ) ;
// Or return it
return result ;
} )
. catch ( ( error ) => {
throw error ;
} ) ;filesstring | arraynode_modules و bower_components . configFilestring(JSON, YAML, or CommonJS) أو اسم وحدة في node_modules التي تشير إلى واحدة.configFile ، فسيقوم WebFont بالبحث عن شجرة الدليل لملف التكوين في الأماكن التالية ، في هذا الترتيب:webfont في package.json.webfontrc .json .yaml .jswebfont.config.js تصدير object JS. سيبدأ البحث في دليل العمل وينتقل إلى شجرة الدليل حتى يجد ملف تكوين. fontNamestringwebfontformatsarray ،['svg', 'ttf', 'eot', 'woff', 'woff2'] ،svg, ttf, eot, woff, woff2 ،template اكتب: string
الافتراضي: null
القيم المحتملة: css ، scss ، styl (لا تتردد في المساهمة أكثر).
ملاحظة: إذا كنت تريد استخدام قالب مخصص ، فاستخدم تمريرة هذا الخيار في string مسار مثل هذا:
webfont ( {
template : "./path/to/my-template.css" ,
} ) ;أو
webfont ( {
template : path . resolve ( __dirname , "./my-template.css" ) ,
} ) ;أو
webfont ( {
template : path . resolve ( __dirname , "./my-template.styl" ) ,
} ) ; templateClassNamestringnulltemplateFontPathstring./CSS . templateFontNamestringfontName إذا لم يتم تعيينه ، ولكن يمكنك تحديد أي قيمة.ligaturesbooleantrueglyphTransformFn النوع: function
الافتراضي: null
الوصف: إذا كنت ترغب في تحويل بيانات تعريف Glyph (على سبيل المثال عناوين فئات CSS أو Unicode) قبل نقلها في قالب أسلوبك لرموزك ، يمكنك استخدام هذا الخيار مع كائن بيانات التعريف Glyphs.
مثال:
import webfont from "webfont" ;
webfont ( {
files : "src/svg-icons/**/*.svg" ,
glyphTransformFn : ( obj ) => {
obj . name += "_transform" ;
something ( ) ;
return obj ;
} ,
} )
. then ( ( result ) => {
// Do something with result
Function . prototype ( result ) ;
// Or return it
return result ;
} )
. catch ( ( error ) => {
throw error ;
} ) ; sortbooltrueيمكن إلحاقها بخيارات WebFont. يتم تمرير هذه مباشرة إلى svgicons2svgfont.
svgicons2svgfont.fontNamestringsvgicons2svgfont.fontIdstringfontNamesvgicons2svgfont.fontStylestring''svgicons2svgfont.fontWeightstring''svgicons2svgfont.fixedWidthbooleanfalsesvgicons2svgfont.centerHorizontallybooleanfalsesvgicons2svgfont.normalizebooleanfalsesvgicons2svgfont.fontHeightnumberMAX(icons.height)svgicons2svgfont.roundnumber10e12 SETUP SVG PATH Rounding. svgicons2svgfont.descentnumber0svgicons2svgfont.ascentnumberfontHeight - descentsvgicons2svgfont.metadatastringundefinedsvgicons2svgfont.logfunctionconsole.logfunction(){} لتعطيل التسجيل. واجهة استخدام سطر الأوامر تبسيط إلى حد ما في هذه المرحلة ، كما هو موضح في قسم الاستخدام التالي.
أضف البرنامج النصي cli إلى كائن scripts الخاصة بملف CLI إلى package.json :
{
"scripts" : {
"webfont" : " node node_modules/webfont/dist/cli.js "
}
}إذا كنت تستخدم Cross-ENV:
{
"scripts" : {
"webfont" : " cross-env node_modules/webfont/dist/cli.js "
}
} Usage: webfont [input] [options]
Input: File(s) or glob(s).
If an input argument is wrapped in quotation marks, it will be passed to " fast-glob "
for cross-platform glob support.
Options:
--config
Path to a specific configuration file (JSON, YAML, or CommonJS)
or the name of a module in ` node_modules ` that points to one.
If no ` --config ` argument is provided, webfont will search for
configuration files in the following places, in this order:
- a ` webfont ` property in ` package.json `
- a ` .webfontrc ` file (with or without filename extension:
` .json ` , ` .yaml ` , and ` .js ` are available)
- a ` webfont.config.js ` file exporting a JS object
The search will begin in the working directory and move up the
directory tree until a configuration file is found.
-f, --font-name
The font family name you want, default: " webfont " .
-h, --help
Output usage information.
-v, --version
Output the version number.
-r, --formats
Only this formats generate.
-d, --dest
Destination for generated fonts.
-m, --dest-create
Create destination directory if it does not exist.
-t, --template
Type of template ( ` css ` , ` scss ` , ` styl ` ) or path to custom template.
'
-s, --dest-template
Destination for generated template. If not passed used `dest` argument value.
-c, --template-class-name
Class name in css template.
-p, --template-font-path
Font path in css template.
-n, --template-font-name
Font name in css template.
--no-sort
Keeps the files in the same order of entry
--verbose
Tell me everything!.
For "svgicons2svgfont":
--font-id
The font id you want, default as "--font-name".
--font-style
The font style you want.
--font-weight
The font weight you want.
--fixed-width
Creates a monospace font of the width of the largest input icon.
--center-horizontally
Calculate the bounds of a glyph and center it horizontally.
--normalize
Normalize icons by scaling them to the height of the highest icon.
--font-height
The outputted font height [MAX(icons.height)].
--round
Setup the SVG path rounding [10e12].
--descent
The font descent [0].
--ascent
The font ascent [height - descent].
--start-unicode
The start unicode codepoint for files without prefix [0xEA01].
--prepend-unicode
Prefix files with their automatically allocated unicode codepoint.
--metadata
Content of the metadata tag.
--add-hash-in-font-url
Generated font url will be : [webfont].[ext]?v=[hash]
يمكن لـ CLI الخروج من العملية باستخدام رموز الخروج التالية:
webpack Plugin.ttf2woff2 مع مكتبة JS الأصلية) ؛لا تتردد في دفع الكود الخاص بك إذا كنت توافق على النشر تحت رخصة معهد ماساتشوستس للتكنولوجيا.
تحقق من changelog لدينا
تحقق من ترخيصنا