Ce plugin vous permet de convertir des fichiers .TTF et .otf en divers autres formats de police tels que .eot, .ttf, .svg, .woff et .woff2 à l'aide du package NPM existant fontfacegen .
fontfacegen
fontfile.ttf ---------------> fontfile.ttf
fontfile.eot
fontfile.svg
fontfile.woff
fontfile.woff2
npm install fontfacegen
npm install fontfacegen-webpack-plugin
Exiger le module fontfacegen-webpack-plugin , créez une instance de FontfacegenWebpackPlugin et passez l'instance au tableau des 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' ] } )
]
}Cela générera les fichiers suivants:
dist/fontfile.eotdist/fontfile.ttfdist/fontfile.svgdist/fontfile.woffdist/fontfile.woff2dist/anotherfont.eotdist/anotherfont.ttfdist/anotherfont.svgdist/anotherfont.woffdist/anotherfont.woff2Vous pouvez ensuite référencer ces fichiers dans votre code.
@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;
} Le module fontfacegen-webpack-plugin par défaut exporte une seule classe: FontfacegenWebpackPlugin
Une instance de cet objet est transmise au tableau des plugins des options de configuration de WebPack.
Le constructeur prend un objet comme premier argument:
| Propriété | Description |
|---|---|
| tâches | Tableau de répertoires ou de chemins de fichiers. |
- Répertoire: les fichiers avec l'extension .ttf et .otf dans le répertoire seront convertis. | |
| - Déposer. Ce fichier unique sera converti. | |
| sous-ensemble | Une chaîne ou un tableau avec les caractères souhaitait être inclus à l'intérieur des polices générées. |
La façon la plus simple de contribuer est de mettre ce projet sur GitHub!
https://github.com/daniel-araujo/fontfacegen-webpack-plugin
Si vous avez trouvé un bogue, vous souhaitez suggérer une fonctionnalité ou avoir besoin d'aide, n'hésitez pas à créer un problème sur GitHub:
https://github.com/daniel-araujo/fontfacegen-webpack-plugin/issues