| 1 | # PostCSS Font Format [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 | [<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/postcss-font-format-keywords.svg" height="20">][npm-url]
|
|---|
| 4 | [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/font-format-keywords.svg" height="20">][css-url]
|
|---|
| 5 | [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
|
|---|
| 6 | [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 7 |
|
|---|
| 8 | [PostCSS Font Format Keywords] lets you specify font formats as keywords, following the [CSS Fonts] specification.
|
|---|
| 9 |
|
|---|
| 10 | ```pcss
|
|---|
| 11 | @font-face {
|
|---|
| 12 | src: url(file.woff2) format(woff2);
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | /* becomes */
|
|---|
| 16 |
|
|---|
| 17 | @font-face {
|
|---|
| 18 | src: url(file.woff2) format("woff2");
|
|---|
| 19 | }
|
|---|
| 20 | ```
|
|---|
| 21 |
|
|---|
| 22 | _See prior work by [valtlai](https://github.com/valtlai) here [postcss-font-format-keywords](https://github.com/valtlai/postcss-font-format-keywords)
|
|---|
| 23 | To ensure long term maintenance and to provide the needed features this plugin was recreated based on valtlai's work._
|
|---|
| 24 |
|
|---|
| 25 | ## Usage
|
|---|
| 26 |
|
|---|
| 27 | Add [PostCSS Font Format Keywords] to your project:
|
|---|
| 28 |
|
|---|
| 29 | ```bash
|
|---|
| 30 | npm install postcss @csstools/postcss-font-format-keywords --save-dev
|
|---|
| 31 | ```
|
|---|
| 32 |
|
|---|
| 33 | Use it as a [PostCSS] plugin:
|
|---|
| 34 |
|
|---|
| 35 | ```js
|
|---|
| 36 | const postcss = require('postcss');
|
|---|
| 37 | const postcssFontFormatKeywords = require('@csstools/postcss-font-format-keywords');
|
|---|
| 38 |
|
|---|
| 39 | postcss([
|
|---|
| 40 | postcssFontFormatKeywords(/* pluginOptions */)
|
|---|
| 41 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 42 | ```
|
|---|
| 43 |
|
|---|
| 44 | [PostCSS Font Format Keywords] runs in all Node environments, with special
|
|---|
| 45 | instructions for:
|
|---|
| 46 |
|
|---|
| 47 | | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
|
|---|
| 48 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 49 |
|
|---|
| 50 | ## Options
|
|---|
| 51 |
|
|---|
| 52 | ### preserve
|
|---|
| 53 |
|
|---|
| 54 | The `preserve` option determines whether the original source
|
|---|
| 55 | is preserved. By default, it is not preserved.
|
|---|
| 56 |
|
|---|
| 57 | ```js
|
|---|
| 58 | postcssFontFormatKeywords({ preserve: true })
|
|---|
| 59 | ```
|
|---|
| 60 |
|
|---|
| 61 | ```pcss
|
|---|
| 62 | @font-face {
|
|---|
| 63 | src: url(file.woff2) format(woff2);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | /* becomes */
|
|---|
| 67 |
|
|---|
| 68 | @font-face {
|
|---|
| 69 | src: url(file.woff2) format("woff2");
|
|---|
| 70 | src: url(file.woff2) format(woff2);
|
|---|
| 71 | }
|
|---|
| 72 | ```
|
|---|
| 73 |
|
|---|
| 74 | [postcss]: https://github.com/postcss/postcss
|
|---|
| 75 |
|
|---|
| 76 | [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|---|
| 77 | [css-url]: https://cssdb.org/#font-format-keywords
|
|---|
| 78 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 79 | [npm-url]: https://www.npmjs.com/package/@csstools/postcss-font-format-keywords
|
|---|
| 80 |
|
|---|
| 81 | [CSS Fonts]: https://www.w3.org/TR/css-fonts-4/#font-format-values
|
|---|
| 82 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 83 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 84 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 85 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 86 | [PostCSS Font Format Keywords]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-font-format-keywords
|
|---|