1 | # postcss-minify-font-values [![Build Status][ci-img]][ci]
|
2 |
|
3 | > Minify font declarations with PostCSS.
|
4 |
|
5 | This module will try to minimise the `font-family`, `font-weight` and `font` shorthand
|
6 | properties; it can unquote font families where necessary, detect & remove
|
7 | duplicates, and cut short a declaration after it finds a keyword. For more
|
8 | examples, see the [tests](test).
|
9 |
|
10 | ```css
|
11 | h1 {
|
12 | font:bold 2.2rem/.9 "Open Sans Condensed", sans-serif;
|
13 | }
|
14 |
|
15 | p {
|
16 | font-family: "Helvetica Neue", Arial, sans-serif, Helvetica;
|
17 | font-weight: normal;
|
18 | }
|
19 | ```
|
20 |
|
21 | ```css
|
22 | h1 {
|
23 | font:700 2.2rem/.9 Open Sans Condensed,sans-serif
|
24 | }
|
25 |
|
26 | p {
|
27 | font-family: Helvetica Neue,Arial,sans-serif;
|
28 | font-weight: 400;
|
29 | }
|
30 | ```
|
31 |
|
32 | ## API
|
33 |
|
34 | ### minifyFontValues([options])
|
35 |
|
36 | #### options
|
37 |
|
38 | ##### removeAfterKeyword
|
39 |
|
40 | Type: `boolean`
|
41 | Default: `false`
|
42 |
|
43 | Pass `true` to remove font families after the module encounters a font keyword,
|
44 | for example `sans-serif`.
|
45 |
|
46 | ##### removeDuplicates
|
47 |
|
48 | Type: `boolean`
|
49 | Default: `true`
|
50 |
|
51 | Pass `false` to disable the module from removing duplicated font families.
|
52 |
|
53 | ##### removeQuotes
|
54 |
|
55 | Type: `boolean` | `(prop: string) => '' | 'font' | 'font-family' | 'font-weight'`
|
56 | Default: `true`
|
57 |
|
58 | Pass `false` to disable the module from removing quotes from font families.
|
59 | Note that oftentimes, this is a *safe optimisation* & is done safely. For more
|
60 | details, see [Mathias Bynens' article][mathias].
|
61 |
|
62 | Pass a function to determine whether a css variable is one of `font`, `font-family`, and `font-weight` to determine whether the variable needs to remove quotes.
|
63 |
|
64 | ## Usage
|
65 |
|
66 | ```js
|
67 | postcss([ require('postcss-minify-font-values') ])
|
68 | ```
|
69 |
|
70 | See [PostCSS] docs for examples for your environment.
|
71 |
|
72 | ## Contributors
|
73 |
|
74 | See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
|
75 |
|
76 | # License
|
77 |
|
78 | MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
|
79 |
|
80 | [mathias]: https://mathiasbynens.be/notes/unquoted-font-family
|
81 | [PostCSS]: https://github.com/postcss/postcss
|
82 | [ci-img]: https://travis-ci.org/cssnano/postcss-minify-font-values.svg
|
83 | [ci]: https://travis-ci.org/cssnano/postcss-minify-font-values
|