fontfacegen webpack plugin
1.0.0
此插件允許您使用現有的NPM軟件包fontfacegen將.TTF和.OTF文件轉換為.Eot,.ttf,.svg,.woff和.woff2等各種其他字體格式。
fontfacegen
fontfile.ttf ---------------> fontfile.ttf
fontfile.eot
fontfile.svg
fontfile.woff
fontfile.woff2
npm install fontfacegen
npm install fontfacegen-webpack-plugin
需要模塊fontfacegen-webpack-plugin ,創建一個FontfacegenWebpackPlugin的實例,然後將實例傳遞給插件數組。
const FontfacegenWebpackPlugin = require ( 'fontfacegen-webpack-plugin' )
module . exports = {
entry : 'index.js' ,
output : {
path : 'dist' ,
filename : 'index_bundle.js'
} ,
plugins : [
new FontfacegenWebpackPlugin ( { tasks : [ 'fontfile.ttf' , 'anotherfont.otf' ] } )
]
}這將生成以下文件:
dist/fontfile.eotdist/fontfile.ttfdist/fontfile.svgdist/fontfile.woffdist/fontfile.woff2dist/anotherfont.eotdist/anotherfont.ttfdist/anotherfont.svgdist/anotherfont.woffdist/anotherfont.woff2然後,您可以在代碼中引用這些文件。
@font-face {
src : url ( "dist/fontfile.eot" );
src : url ( "dist/fontfile.eot?#iefix" ) format ( "embedded-opentype" ) ,
url ( "dist/fontfile.woff2" ) format ( "woff2" ) ,
url ( "dist/fontfile.woff" ) format ( "woff" ) ,
url ( "dist/fontfile.ttf" ) format ( "ttf" ) ,
url ( "dist/fontfile.svg" ) format ( "svg" );
font-family : fontfile;
font-style : normal;
font-weight : normal;
}
@font-face {
src : url ( "dist/anotherfont.eot" );
src : url ( "dist/anotherfont.eot?#iefix" ) format ( "embedded-opentype" ) ,
url ( "dist/anotherfont.woff2" ) format ( "woff2" ) ,
url ( "dist/anotherfont.woff" ) format ( "woff" ) ,
url ( "dist/anotherfont.ttf" ) format ( "ttf" ) ,
url ( "dist/anotherfont.svg" ) format ( "svg" );
font-family : anotherfont;
font-style : normal;
font-weight : normal;
}fontfacegen-webpack-plugin模塊默認導出一個類: FontfacegenWebpackPlugin
此對象的實例傳遞給WebPack配置選項的插件陣列。
構造函數將對像作為其第一個參數:
| 財產 | 描述 |
|---|---|
| 任務 | 目錄或文件路徑數組。 |
- 目錄:將轉換為目錄中的帶有.ttf和.otf文件。 | |
| - 文件。該文件將被轉換。 | |
| 子集 | 帶有想要包含在生成字體中的字符的字符串或數組。 |
最簡單的貢獻方法是將該項目主演在Github上!
https://github.com/daniel-araujo/fontfacegen-webpack-plugin
如果您發現一個錯誤,想建議一個功能或需要一些幫助,請隨時在GitHub上創建問題:
https://github.com/daniel-areujo/fontfacegen-webpack-plugin/issues