-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,83 @@ | ||
# uni-helper/unocss-preset-uni | ||
# @uni-helper/unocss-preset-uni | ||
|
||
专为 uni-app 打造的 UnoCSS 预设 | ||
|
||
[![npm version][npm-version-src]][npm-version-href] | ||
[![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
[![bundle][bundle-src]][bundle-href] | ||
[![License][license-src]][license-href] | ||
|
||
## 特性 | ||
|
||
- ⚡️ 零配置启动,就像 `presetUno` 一样! | ||
- 👍 内置 `Attributify` 支持! | ||
- ⚙️ 随时停用或自定义预设的配置 | ||
- 🦾 按平台编写样式! | ||
|
||
## 使用 | ||
|
||
安装 | ||
|
||
```shell | ||
pnpm add @uni-helper/unocss-preset-uni | ||
``` | ||
配置 | ||
|
||
```ts | ||
// uno.config.ts | ||
import { defineConfig } from 'unocss' | ||
import presetUni from '@uni-helper/unocss-preset-uni' | ||
|
||
export default defineConfig({ | ||
presets: [ | ||
presetUni() | ||
] | ||
}) | ||
``` | ||
|
||
## 示例 | ||
|
||
### 按平台编写 | ||
|
||
```html | ||
<div class='uni-h5:mx-auto'></div> | ||
<div class='uni-app:mx-auto'></div> | ||
<div class='uni-app-android:mx-auto'></div> | ||
<div class='uni-mp:mx-auto'></div> | ||
<div class='uni-mp-weixin:mx-auto'></div> | ||
... | ||
``` | ||
|
||
你还可以使用 uno.config 的 theme 来自定义平台匹配规则: | ||
|
||
```ts | ||
export default defineConfig({ | ||
theme: { | ||
platform: { | ||
'wechat': 'mp-weixin', // alias 到 mp-weixin | ||
'my-app': 'my-app', // 自定义平台 | ||
} | ||
} | ||
}) | ||
``` | ||
```html | ||
<div class='uni-wechat:mx-auto'></div> | ||
<div class='uni-my-app:mx-auto'></div> | ||
``` | ||
|
||
## 感谢 | ||
|
||
- [unocss](https://github.com/unocss/unocss.git) 提供大部分函数 | ||
- [unocss-applet](https://github.com/unocss-applet/unocss-applet.git) 提供小程序支持 | ||
- [uni-unocss](https://github.com/okxiaoliang4/uni-unocss) 提供按平台编写灵感 | ||
|
||
<!-- Badges --> | ||
|
||
[npm-version-src]: https://img.shields.io/npm/v/@uni-helper/unocss-preset-uni?style=flat&colorA=18181B&colorB=F0DB4F | ||
[npm-version-href]: https://npmjs.com/package/@uni-helper/unocss-preset-uni | ||
[npm-downloads-src]: https://img.shields.io/npm/dm/@uni-helper/unocss-preset-uni?style=flat&colorA=18181B&colorB=F0DB4F | ||
[npm-downloads-href]: https://npmjs.com/package/@uni-helper/unocss-preset-uni | ||
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@uni-helper/unocss-preset-uni?style=flat&colorA=18181B&colorB=F0DB4F | ||
[bundle-href]: https://bundlephobia.com/result?p=@uni-helper/unocss-preset-uni | ||
[license-src]: https://img.shields.io/github/license/uni-helper/unocss-preset-uni.svg?style=flat&colorA=18181B&colorB=F0DB4F | ||
[license-href]: https://github.com/uni-helper/unocss-preset-uni/blob/main/LICENSE |