Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
vite-svg-2-webfont
Advanced tools
A Vite Plugin that generates fonts from your SVG icons and allows you to use your icons in your HTML.
vite-svg-2-webfont
uses the webfonts-generator
package 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 i -D vite-svg-2-webfont
yarn add -D vite-svg-2-webfont
pnpm add -D vite-svg-2-webfont
Add the plugin to the vite.config.ts
with the wanted setup, and import the virtual module, to inject the icons CSS font to the bundle.
Add the plugin to your vite configs plugin array.
// vite.config.ts
import { resolve } from 'path';
import { defineConfig } from 'vite';
import viteSvgToWebfont from 'vite-svg-2-webfont';
export default defineConfig({
plugins: [
viteSvgToWebfont({
context: resolve(__dirname, 'icons'),
}),
],
});
Import the virtual module into the app
// main.ts
import 'virtual:vite-svg-2-webfont.css';
Use the font in templates with the icon font class and an icon class name.
The default font class name is .icon
and can be overriden by passing the baseSelector
configuration option.
Icon class names are derived from their .svg
file name, and prefixed with the value of classPrefix
which defaults to icon-
.
In the below example, the add
class would display the icon created from the file {context}/add.svg
<i class="icon icon-add"></i>
The plugin has an API consisting of one required parameter and multiple optional parameters allowing to fully customize plugin setup.
string
svg
files will execute. The SVG files will be used to generate the icon font.string
['*.svg']
string
'iconfont'
string
path.resolve(context, '..', 'artifacts')
string
path.join(dest, fontName + '.css')
type: string
description: Path of custom CSS template. Generator uses handlebars templates. Tht template receives options from templateOptions
along with the following options:
string
– Value of the src
property for @font-face
.object
- Codepoints of icons in hex format.Paths of default templates are stored in the webfontsGenerator.templates
object.
webfontsGenerator.templates.css
– Default CSS template path. It generates classes with names based on values from options.templateOptions
.webfontsGenerator.templates.scss
– Default SCSS template path. It generates mixin webfont-icon
to add icon styles. It is safe to use multiple generated files with mixins together.string
cssDest
string
path.join(dest, fontName + '.html')
string
options.templateOptions
along with the following options:
string
– Styles generated with default CSS template. (cssFontsPath
is changed to relative path from htmlDest
to dest
)string[]
– Names of icons.boolean
true
boolean
false
number
10e12
number
0
boolean
false
number
boolean
false
boolean | string | string[]
true
Generate all file types.false
Generate no files.'html'
- Generate a HTML file'css'
- Generate CSS file'fonts'
- Generate font files (based on the types requested)false
string | string[]
svg
ttf
woff
woff2
eot
['eot', 'woff', 'woff2', 'ttf', 'svg']
{ [key: string]: number }
startCodepoint
skipping duplicates.string
'icon-'
string
'.icon'
{ [format in 'svg' | 'ttf' | 'woff2' | 'woff' | 'eot']?: unknown };
string
'vite-svg-2-webfont.css'
boolean
false
boolean
false
The plugin exposes a public API that can be used inside another plugins using Rollup inter-plugin communication mechanism.
Currently available methods:
Array<{ type: 'svg' | 'ttf' | 'woff2' | 'woff' | 'eot', href: string }>
type
- a font format generated by a pluginhref
- a path to a generated fontFAQs
A vite plugin which generates a webfont out of svg icons
The npm package vite-svg-2-webfont receives a total of 800 weekly downloads. As such, vite-svg-2-webfont popularity was classified as not popular.
We found that vite-svg-2-webfont demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.