webfont
11.2.20 (2021-07-31)
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將按以下位置搜索目錄樹以查找配置文件:package.json中的webfont屬性.webfontrc文件(有或沒有文件名擴展名: .json , .yaml和.js可用)webfont.config.js文件導出JS object 。搜索將從工作目錄開始,然後向上移動目錄樹,直到找到配置文件為止。 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 Metadata(例如CSS類或Unicode的標題),則可以使用Glyphs Metadata對象使用此選項。
例子:
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.fontIdstringfontName值svgicons2svgfont.fontStylestring''svgicons2svgfont.fontWeightstring''svgicons2svgfont.fixedWidthbooleanfalsesvgicons2svgfont.centerHorizontallybooleanfalsesvgicons2svgfont.normalizebooleanfalsesvgicons2svgfont.fontHeightnumberMAX(icons.height)svgicons2svgfont.roundnumber10e12設置SVG路徑舍入。 svgicons2svgfont.descentnumber0svgicons2svgfont.ascentnumberfontHeight - descentsvgicons2svgfont.metadatastringundefinedsvgicons2svgfont.logfunctionconsole.logfunction(){}以禁用日誌記錄。 在此階段,命令行使用的接口相當簡單,如以下用法部分所示。
將cli腳本添加到您的package.json文件的scripts對象:
{
"scripts" : {
"webfont" : " node node_modules/webfont/dist/cli.js "
}
}如果您使用的是交叉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插件。ttf2woff2 );如果您同意根據MIT許可發布發布,請隨時推動代碼。
檢查我們的變形值
檢查我們的許可證