2023-12-21 17:30:49 +08:00
|
|
|
|
// uno.config.ts
|
|
|
|
|
import {
|
2024-02-23 09:54:50 +08:00
|
|
|
|
Preset,
|
2023-12-21 17:30:49 +08:00
|
|
|
|
defineConfig,
|
|
|
|
|
presetAttributify,
|
|
|
|
|
presetIcons,
|
|
|
|
|
transformerDirectives,
|
|
|
|
|
transformerVariantGroup,
|
|
|
|
|
} from 'unocss'
|
|
|
|
|
|
2024-02-23 09:54:50 +08:00
|
|
|
|
import {
|
|
|
|
|
presetApplet,
|
|
|
|
|
presetRemRpx,
|
|
|
|
|
transformerApplet,
|
|
|
|
|
transformerAttributify,
|
|
|
|
|
} from 'unocss-applet'
|
|
|
|
|
|
2024-04-12 14:58:44 +08:00
|
|
|
|
// @see https://unocss.dev/presets/legacy-compat
|
|
|
|
|
import presetLegacyCompat from '@unocss/preset-legacy-compat'
|
|
|
|
|
|
2024-02-23 09:54:50 +08:00
|
|
|
|
const isH5 = process.env?.UNI_PLATFORM === 'h5'
|
|
|
|
|
const isMp = process.env?.UNI_PLATFORM?.startsWith('mp') ?? false
|
2023-12-23 09:47:04 +08:00
|
|
|
|
|
2024-02-23 09:54:50 +08:00
|
|
|
|
const presets: Preset[] = []
|
|
|
|
|
if (!isMp) {
|
|
|
|
|
/**
|
|
|
|
|
* you can add `presetAttributify()` here to enable unocss attributify mode prompt
|
|
|
|
|
* although preset is not working for applet, but will generate useless css
|
|
|
|
|
* 为了不生产无用的css,要过滤掉 applet
|
|
|
|
|
*/
|
|
|
|
|
// 支持css class属性化,eg: `<button bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600" text="sm white">attributify Button</button>`
|
|
|
|
|
presets.push(presetAttributify())
|
|
|
|
|
}
|
2024-03-17 12:08:04 +08:00
|
|
|
|
if (!isH5) {
|
|
|
|
|
presets.push(presetRemRpx())
|
|
|
|
|
}
|
2023-12-21 17:30:49 +08:00
|
|
|
|
export default defineConfig({
|
|
|
|
|
presets: [
|
2024-02-23 09:54:50 +08:00
|
|
|
|
presetApplet({ enable: !isH5 }),
|
|
|
|
|
...presets,
|
2023-12-21 17:30:49 +08:00
|
|
|
|
// 支持图标,需要搭配图标库,eg: @iconify-json/carbon, 使用 `<button class="i-carbon-sun dark:i-carbon-moon" />`
|
|
|
|
|
presetIcons({
|
|
|
|
|
scale: 1.2,
|
|
|
|
|
warn: true,
|
|
|
|
|
extraProperties: {
|
|
|
|
|
display: 'inline-block',
|
|
|
|
|
'vertical-align': 'middle',
|
|
|
|
|
},
|
|
|
|
|
}),
|
2024-04-12 14:58:44 +08:00
|
|
|
|
// 将颜色函数 (rgb()和hsl()) 从空格分隔转换为逗号分隔,更好的兼容性app端,example:
|
|
|
|
|
// `rgb(255 0 0)` -> `rgb(255, 0, 0)`
|
|
|
|
|
// `rgba(255 0 0 / 0.5)` -> `rgba(255, 0, 0, 0.5)`
|
|
|
|
|
presetLegacyCompat({
|
|
|
|
|
commaStyleColorFunction: true,
|
|
|
|
|
}) as Preset,
|
2023-12-21 17:30:49 +08:00
|
|
|
|
],
|
2024-01-29 12:58:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* 自定义快捷语句
|
|
|
|
|
* @see https://github.com/unocss/unocss#shortcuts
|
|
|
|
|
*/
|
|
|
|
|
shortcuts: [['center', 'flex justify-center items-center']],
|
2023-12-21 17:30:49 +08:00
|
|
|
|
transformers: [
|
2024-01-29 12:58:59 +08:00
|
|
|
|
// 启用 @apply 功能
|
2023-12-21 17:30:49 +08:00
|
|
|
|
transformerDirectives(),
|
2024-01-29 12:58:59 +08:00
|
|
|
|
// 启用 () 分组功能
|
2023-12-21 17:30:49 +08:00
|
|
|
|
// 支持css class组合,eg: `<div class="hover:(bg-gray-400 font-medium) font-(light mono)">测试 unocss</div>`
|
|
|
|
|
transformerVariantGroup(),
|
2024-02-23 09:54:50 +08:00
|
|
|
|
// Don't change the following order
|
2024-03-06 09:11:59 +08:00
|
|
|
|
transformerAttributify({
|
|
|
|
|
// 解决与第三方框架样式冲突问题
|
|
|
|
|
prefixedOnly: true,
|
|
|
|
|
prefix: 'fg',
|
|
|
|
|
}),
|
2024-02-23 09:54:50 +08:00
|
|
|
|
transformerApplet(),
|
|
|
|
|
],
|
|
|
|
|
rules: [
|
|
|
|
|
[
|
|
|
|
|
'p-safe',
|
|
|
|
|
{
|
|
|
|
|
padding:
|
|
|
|
|
'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
['pt-safe', { 'padding-top': 'env(safe-area-inset-top)' }],
|
|
|
|
|
['pb-safe', { 'padding-bottom': 'env(safe-area-inset-bottom)' }],
|
2023-12-21 17:30:49 +08:00
|
|
|
|
],
|
|
|
|
|
})
|
2024-02-23 09:56:18 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 最终这一套组合下来会得到:
|
|
|
|
|
* mp 里面:mt-4 => margin-top: 32rpx
|
|
|
|
|
* h5 里面:mt-4 => margin-top: 1rem
|
|
|
|
|
*/
|