mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 12:38:39 +00:00
Include only necessary fonts for target environment specified by Browserslist (#1674)
* Include only necessary fonts for target environment specified by Browserslist Allow WOFF and WOFF2 to be controlled using environment variables * Fix links * Fix merge error * Update dependencies * Replace uglifyjs-webpack-plugin with terser-webpack-plugin * Do not set `targets` if !isESMBuild
This commit is contained in:
committed by
Kevin Barabash
parent
64745b5c8a
commit
ce3840d4ce
18
docs/font.md
18
docs/font.md
@@ -25,19 +25,17 @@ will appear larger than 1cm in browser units.
|
||||
|
||||
## Kinds of fonts used
|
||||
|
||||
The default build of KaTeX includes each of the needed fonts in three different formats: `ttf`, `woff`, and `woff2`.
|
||||
KaTeX provides fonts in three different formats: `ttf`, `woff`, and `woff2`.
|
||||
|
||||
- `ttf`s are included to support old versions of Chrome, Safari, Firefox, etc. (Here "old" means Firefox 3.5, Chrome < 5, and Safari <= 5.1, all of which are no longer supported: see [woff](https://caniuse.com/#search=woff) vs. [ttf](https://caniuse.com/#search=ttf)).
|
||||
- `woff` is the format that is most widely supported (all modern browsers support it), so it probably provides the most benefit to being included.
|
||||
- `woff2`s are included for very new versions of Chrome, because they are much smaller and faster to load.
|
||||
- `ttf`s are included to support very old browsers and local installation. [Browser support](https://caniuse.com/#feat=ttf)
|
||||
- `woff` is the format that is most widely supported (all modern browsers support it), so it probably provides the most benefit to being included. [Browser support](https://caniuse.com/#feat=woff)
|
||||
- `woff2`s are included for modern browsers, because they are much smaller and faster to load. [Browser support](https://caniuse.com/#feat=woff2)
|
||||
|
||||
Based on this information and what you want to support with your website, you might decide to include different versions of the fonts besides what comes with the standard installation.
|
||||
KaTeX will automatically include only necessary fonts for target environments
|
||||
specified by [Browserslist config](https://github.com/browserslist/browserslist#queries).
|
||||
|
||||
For example, if you wanted to create a trimmed down version of KaTeX, you could only include the `woff` files and gain the most support with the least number of files. To do this:
|
||||
|
||||
1. Set `@use-ttf`, and `@use-woff2` to `false` at the top of [fonts.less](https://github.com/KaTeX/katex-fonts/blob/master/fonts.less).
|
||||
2. Rebuild KaTeX by running `yarn build` from the top-level directory.
|
||||
3. Include only the `build/fonts/*.woff` files in your distribution.
|
||||
To force a font type to be included or excluded, set `USE_(FONT NAME)` environment
|
||||
variable to `"true"` or `"false"`, respectively.`
|
||||
|
||||
## Location of font files
|
||||
|
||||
|
10
docs/node.md
10
docs/node.md
@@ -36,6 +36,16 @@ yarn
|
||||
yarn build
|
||||
```
|
||||
|
||||
It will automatically transpile code and include only necessary fonts for
|
||||
target environments specified by [Browserslist config](https://github.com/browserslist/browserslist#environment-variables).
|
||||
For example, if you are making a web app for a kiosk with Chrome 68, run
|
||||
`BROWSERSLIST="Chrome 68" yarn build` and it will produce build with no
|
||||
transpilation, as it fully supports ES6, and only include WOFF2 fonts.
|
||||
|
||||
You can override included fonts using environment variables. Set `USE_(FONT NAME)`
|
||||
environment variable to `"true"` or `"false"`, to force a font type to be included
|
||||
or excluded, respectively.`
|
||||
|
||||
If you'd like to use the built KaTeX in other projects, install the package by
|
||||
specifying the path:
|
||||
```bash
|
||||
|
Reference in New Issue
Block a user