Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
webfonts-loader
Advanced tools
A WebPack loader to automaticaly generate font files and CSS to make your own icon font
A Webpack loader that generates fonts from your SVG icons and allows you to use your icons in your HTML.
webfonts-loader
uses the webfonts-generator
plugin to create fonts in any format. It also generates CSS files so that you can use your icons directly in your HTML, using CSS classes.
npm install webfonts-loader
An example of usage can be found in the test/
directory of this repository.
Add this rule to your Webpack config:
{
test: /\.font\.js/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'webfonts-loader'
]
}
So that each font configuration file will be loaded using this rule.
You can provide options
objects to configure the loader behaviour:
{
test: /\.font\.js/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'webfonts-loader',
options: { ... }
}
]
}
Available options are:
publicPath
, StringThis is the URL prefix for generated links (e.g. /static/
or https://cdn.project.net/
). Should typically match Webpack's config.output.publicPath
.
If you pass types
, fileName
or any other font config option, it will be used as a default (unless overriden in font config file).
The config file allows you to specify parameters for the loader to use. Here is an example configuration file:
// myfont.font.js
module.exports = {
'files': [
'./myfont/*.svg'
],
'fontName': 'myfonticons',
'classPrefix': 'myfonticon-',
'baseSelector': '.myfonticon',
'types': ['eot', 'woff', 'woff2', 'ttf', 'svg'],
'fileName': 'app.[fontname].[hash].[ext]'
};
Then you have to require the configuration file:
// entry.js
require('./myfont.font');
The loader will then generate:
baseSelector
, StringThe base CSS selector, under which each icon class is to be created. See webfonts-generator#templateOptions
classPrefix
, StringThe prefix to be used with each icon class. See webfonts-generator#templateOptions
cssTemplate
, StringSee webfonts-generator#cssTemplate
cssDest
, StringSee webfonts-generator#cssDest
embed
, BooleanIf true the font is encoded in base64 and embedded inside the @font-face
declaration, otherwise font files are written to disk.
Default: false
scssFile
, BooleanIf true, the build process will export a .scss file in the same path as the .css file.
Default: false
hashLength
, NumberOptional. The length of hash in fileName
.
Min: 8
Max: 32
Default: 20
fileName
, StringThe generated font file names. These elements can be used:
[fontname]
: the value of the fontName
parameter[ext]
: the extension of the font file being generated (eot
, ...)[hash]
: the hash of the current compilation[chunkhash]
: the hash of the SVG filesThis option can be also configured globally in the webpack loader options.
emitCodepoints
, Array (with shorthand versions of Boolean, String and Object)Optional. The generated codepoints file names.
Examples:
emitCodepoints: true
: emits a javascript file named [fontname].codepoints.js
in the web
(default) formatemitCodepoints: '[fontname].codepoints.fonts.js'
: emits a javascript file named [fontname].codepoints.fonts.js
in the commonjs
formatemitCodepoints: { fileName: '[fontname].codepoints.json', type: 'json'] }
: emits a file named [fontname].codepoints.json
in the json
formatemitCodepoints: [{ fileName: '[fontname].codepoints.json', type: 'json'] }, { fileName: '[fontname].codepoints.js', type: 'web'] }, { fileName: '[fontname].codepoints.inc.js', type: 'web'] }]
: emits three files with their respective names and typesThese are the existing formats:
web
: (default): generates a file containing the array of codepoints in a format suitable for inclusion in html pages.Example (for a font named myfonticons):
if (typeof webfontIconCodepoints === 'undefined') {
webfontIconCodepoints = {};
}
webfontIconCodepoints["myfonticons"] = {"alert":61697,"arrow-down":61698,"arrow-left":61699};
commonjs
: generates a file containing the array of codepoints in the commonjs format, for use with require
.module.exports = {"alert":61697,"arrow-down":61698,"arrow-left":61699}
json
: generates a file containing the array of codepoints in the JSON format.{"alert":61697,"arrow-down":61698,"arrow-left":61699,"arrow-right":61700,"arrow-small-down":61701}
These elements can be used in the filename:
[fontname]
: the value of the fontName
parameter[chunkhash]
: the hash of the SVG filesThis option can be also configured globally in the webpack loader options.
files
, ArrayfontName
, StringSee webfonts-generator#fontname
formatOptions
, ObjectSee webfonts-generator#formatoptions
rename
, Functiontypes
, Arraydest
, Stringhtml
, BooleanhtmlDest
, StringSee webfonts-generator#htmldest
writeFiles
, Boolean (default false)See webfonts-generator#writefiles
ligature
, BooleanSee webfonts-generator#ligature
cssFontsUrl
, String (before cssFontsPath)See webfonts-generator#cssfontspath
htmlTemplate
, String...
htmlTemplate: path.resolve(__dirname, 'src/html.hbs'),
...
FAQs
A WebPack loader to automatically generate font files and CSS to make your own icon font
The npm package webfonts-loader receives a total of 9,632 weekly downloads. As such, webfonts-loader popularity was classified as popular.
We found that webfonts-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.