Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tengfei5000nian/static-font-min-loader
一个webpack的loader,用来压缩生成字体。
https://github.com/tengfei5000nian/static-font-min-loader
font webpack webpack-loader
Last synced: 7 days ago
JSON representation
一个webpack的loader,用来压缩生成字体。
- Host: GitHub
- URL: https://github.com/tengfei5000nian/static-font-min-loader
- Owner: tengfei5000nian
- License: mit
- Created: 2022-09-16T06:42:56.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-24T10:38:50.000Z (over 2 years ago)
- Last Synced: 2024-12-20T08:36:09.140Z (about 2 months ago)
- Topics: font, webpack, webpack-loader
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fontmin loader for webpack
一个webpack的loader,用来压缩生成字体。
> NOTE: Node v10+ and webpack v4+ are supported and tested.
## 关于
读取指定文件文本,使用fontmin压缩用到的字体。
## 安装
`npm install --save-dev static-font-min-loader`
## 使用
```js
const webpackConfig = {
module: {
rules: [
{
test: /\.(otf|ttf|svg|svgs|eot|woff|woff2)(\?.*)?$/,
type: 'javascript/auto',
loader: 'static-font-min-loader',
options: {
fileLoaderOptions: {
name: 'font/[name].[hash:8].[ext]'
}
}
}
]
}
}module.exports = webpackConfig
``````css
@font-face {
font-family: 'source';
src:
url('../font/source.ttf?to=eot') format('embedded-opentype'),
url('../font/source.ttf?to=woff2') format('woff2'),
url('../font/source.ttf?to=woff') format('woff'),
url('../font/source.ttf?to=svg') format('svg'),
url('../font/source.ttf') format('truetype');
}
```在source.ttf的文件夹中创建source.txt文本文件,里面包含需要压缩的文字。
## 选项
```js
{
// 包含需要切割的文本的文件, 如果include、exclude存在,links失效。
//
// type: array|string
// default: loaderContext.resourcePath.replace(/\.([\w\d]+)$/, '.txt')
links: [],// 包含的文件。
//
// type: RegExp?
include: null,// 排除的文件
//
// type: RegExp?
exclude: null,// 文本过滤。
//
// type: function(text: string): string
filter: text => text,// file-loader的options。
// See https://github.com/webpack-contrib/file-loader
//
// type: object?
fileLoaderOptions: {}
}
```