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