Este plug -in permite converter arquivos .ttf e .otf em vários outros formatos de fonte, como .eot, .ttf, .svg, .woff e .woff2 usando o pacote npm existente fontfacegen .
fontfacegen
fontfile.ttf ---------------> fontfile.ttf
fontfile.eot
fontfile.svg
fontfile.woff
fontfile.woff2
npm install fontfacegen
npm install fontfacegen-webpack-plugin
Exigir o módulo fontfacegen-webpack-plugin , crie uma instância de FontfacegenWebpackPlugin e passe a instância para a matriz de plugins.
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' ] } )
]
}Isso gerará os seguintes arquivos:
dist/fontfile.eotdist/fontfile.ttfdist/fontfile.svgdist/fontfile.woffdist/fontfile.woff2dist/anotherfont.eotdist/anotherfont.ttfdist/anotherfont.svgdist/anotherfont.woffdist/anotherfont.woff2Você pode fazer referência a esses arquivos em seu código.
@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;
} O módulo fontfacegen-webpack-plugin exporta uma única classe: FontfacegenWebpackPlugin
Uma instância desse objeto é passada para a matriz de plugins das opções de configuração do WebPack.
O construtor toma um objeto como seu primeiro argumento:
| Propriedade | Descrição |
|---|---|
| tarefas | Matriz de diretórios ou caminhos de arquivo. |
- Diretório: arquivos com a extensão .ttf e .otf no diretório serão convertidos. | |
| - Arquivo. Esse arquivo único será convertido. | |
| subconjunto | Uma string ou matriz com os caracteres desejados para serem incluídos dentro das fontes geradas. |
A maneira mais fácil de contribuir é estrelando este projeto no Github!
https://github.com/daniel-araujo/fontfacegen-webpack-plugin
Se você encontrou um bug, gostaria de sugerir um recurso ou precisar de ajuda, sinta -se à vontade para criar um problema no Github:
https://github.com/daniel-araujo/fontfacegen-webpack-plugin/issues