postcss-webfont
is PostCSS plugin for generating web fonts from stylesheets.
npm install postcss-webfont --save-dev
yarn add postcss-webfont --dev
const postcss = require('postcss');
const webfont = require('postcss-webfont');
const options = {
outputPath: './dist/fonts/'
};
postcss([webfont(options)])
.process(css)
.then(function(result) {
fs.writeFileSync('./dist/style.css', result.css);
});
Your base path that will be used for svg files with absolute CSS urls.
Type: String
Default: ./
Relative path to the directory that will keep your output font file.
Type: String
Default: ./
Relative path to the base directory that will keep your stylesheet file.
Type: String
Default: ./
The url to the output directory resolved relative to the HTML page.
Type: String
Default: ``
The cache file path of generated fonts.
Type: String
Default: .fontcache.json
The output formats of font-face src property.
Type: Array<String>
Default: ['ttf', 'eot', 'woff']
Starting codepoint used for the generated glyphs.
Type: Integer
Default: 0xEA01
Prefix files with their automatically allocated unicode code point.
Type: Boolean
Default: false
The vertical-align property value.
Type: String
Default: middle
The generating class name prefix.
Type: String
Default: iconfont
The generating class name prefix for before pseudo element.
Type: String
Default: before
The generating class name prefix for after pseudo element.
Type: String
Default: after
The cachebuster type.
To disable is specified null or undefined.
Cachebuster types:
- hash : Generating font hash.
- fixed : Fixed cachebuster. The fixed value is specified
cachebusterFixed
option.
Type: String
Default: hash
The fixed cachebuster value.
Type: String
Default: ``
The options of svgicons2svgfont are available:
- options.fontWeight
- options.fontStyle
- options.fixedWidth
- options.centerHorizontally
- options.normalize
- options.fontHeight
- options.round
- options.descent
├─┬ css/
│ └─ style.css
├── fonts/
└─┬ svg/
├─ arrow-up-left.svg
└─ arrow-up-right.svg
style.css
// before
@font-face {
font-family: 'font-awesome';
src: url('./fonts/*.svg');
font-weight: normal;
font-style: normal;
font-display: swap;
}
// after
@font-face {
font-family: 'font-awesome';
src: url('./fonts/font-awesome.eot');
src: url('./fonts/font-awesome.eot#iefix') format('embedded-opentype'),
url('./fonts/font-awesome.ttf') format('truetype'),
url('./fonts/font-awesome.woff') format('woff'),
url('./fonts/font-awesome.svg?#font-awesome') format('svg');
font-weight: normal;
font-style: normal;
font-display: swap;
}
[class^='iconfont-font-awesome-']::before, [class*=' iconfont-font-awesome-']::before,
[class^='iconfont-before-font-awesome-']::before, [class*=' iconfont-before-font-awesome-']::before,
[class^='iconfont-after-font-awesome-']::after, [class*=' iconfont-after-font-awesome-']::after {
font-family: 'font-awesome', sans-serif;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
vertical-align: middle;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.iconfont-font-awesome-arrow-up-left::before {
content: '\EA01';
}
.iconfont-before-font-awesome-arrow-up-left::before {
content: '\EA01';
}
.iconfont-after-font-awesome-arrow-up-right::after {
content: '\EA02';
}