Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lete114/rollup-plugin-font-minify
Remove unused font glyphs from the project during packaging to reduce font file size
https://github.com/lete114/rollup-plugin-font-minify
Last synced: 14 days ago
JSON representation
Remove unused font glyphs from the project during packaging to reduce font file size
- Host: GitHub
- URL: https://github.com/lete114/rollup-plugin-font-minify
- Owner: Lete114
- License: mit
- Created: 2024-01-03T11:44:44.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-05-01T13:26:57.000Z (7 months ago)
- Last Synced: 2024-10-11T07:52:43.849Z (about 1 month ago)
- Language: JavaScript
- Size: 6.68 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rollup-plugin-font-minify
Remove unused font glyphs from the project during packaging to reduce font file size
## Install
Using npm:
```bash
npm install rollup-plugin-font-minify --save-dev
```## Usage
If you are using [rollup](https://www.rollupjs.org)
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
```js
// rollup.config.js
import fontmin from 'rollup-plugin-font-minify'export default {
input: 'src/index.js',
output: {
// ...
},
plugins: [fontmin()]
}
```If you are using [vite](https://vitejs.dev)
Create a `vite.config.js` [configuration file](https://vitejs.dev/config/) and import the plugin:
```js
// vite.config.js
import fontmin from 'rollup-plugin-font-minify'export default {
plugins: [fontmin()]
}
```## Options
### `reserveText`
Type: `String`
Default: `''`Text to be reserved.
This option can be used in certain scenarios where data obtained by sending a request needs to be displayed on the page and fonts are used.
The reserved font glyphs you specify will be retained during packaging.### `filter`
Type: `(text: string) => string`
Default: `null`Filter text to keep only what is needed
This is an example: compress only specified characters, e.g. only [CJK](https://wikipedia.org/wiki/CJK_characters) (CJK Unified Ideographs) characters
```js
function getCJK(str) {
const reg = /[\u4E00-\u9FA5\u3040-\u30FF\u31F0-\u31FF\uFF00-\uFF9F\u3000-\u303F\uFF01-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF40\uFF5B-\uFF60\uFFE0-\uFFE6]/g
const cjkChars = str.match(reg)
return cjkChars ? cjkChars.join('') : ''
}plugins: [
fontmin({
filter(text) {
return getCJK(text)
}
})
]
```## Meta
[LICENSE (MIT)](/LICENSE)