Este complemento le permite convertir archivos .TTF y .OTF en otros formatos de fuentes como .eot, .ttf, .svg, .woff y .woff2 utilizando el paquete NPM existente fontfacegen .
fontfacegen
fontfile.ttf ---------------> fontfile.ttf
fontfile.eot
fontfile.svg
fontfile.woff
fontfile.woff2
npm install fontfacegen
npm install fontfacegen-webpack-plugin
Requerir el módulo fontfacegen-webpack-plugin , cree una instancia de FontfacegenWebpackPlugin y pase la instancia a la matriz de complementos.
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' ] } )
]
}Esto generará los siguientes archivos:
dist/fontfile.eotdist/fontfile.ttfdist/fontfile.svgdist/fontfile.woffdist/fontfile.woff2dist/anotherfont.eotdist/anotherfont.ttfdist/anotherfont.svgdist/anotherfont.woffdist/anotherfont.woff2Luego puede hacer referencia a estos archivos en su 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;
} El módulo fontfacegen-webpack-plugin predeterminado exporta una sola clase: FontfacegenWebpackPlugin
Se pasa una instancia de este objeto a la matriz de complementos de las opciones de configuración de Webpack.
El constructor toma un objeto como su primer argumento:
| Propiedad | Descripción |
|---|---|
| tareas | Gama de directorios o rutas de archivo. |
- Directorio: los archivos con la extensión .ttf y .otf en el directorio se convertirán. | |
| - Archivo. Ese archivo único se convertirá. | |
| subconjunto | Una cadena o una matriz con los caracteres deseados para incluir dentro de las fuentes generadas. |
¡La forma más fácil de contribuir es protagonizar este proyecto en GitHub!
https://github.com/daniel- noJo/fontfacen-webpack-plugin
Si ha encontrado un error, le gustaría sugerir una función o necesitar ayuda, no dude en crear un problema en GitHub:
https://github.com/daniel- noamo/fontfacen-webpack-plugin/issues