98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import type {
|
||
Preset,
|
||
} from 'unocss'
|
||
// https://www.npmjs.com/package/@uni-helper/unocss-preset-uni
|
||
import { presetUni } from '@uni-helper/unocss-preset-uni'
|
||
|
||
// @see https://unocss.dev/presets/legacy-compat
|
||
import { presetLegacyCompat } from '@unocss/preset-legacy-compat'
|
||
import {
|
||
defineConfig,
|
||
presetAttributify,
|
||
presetIcons,
|
||
transformerDirectives,
|
||
transformerVariantGroup,
|
||
} from 'unocss'
|
||
|
||
export default defineConfig({
|
||
presets: [
|
||
presetUni({
|
||
attributify: false,
|
||
}),
|
||
presetIcons({
|
||
scale: 1.2,
|
||
warn: true,
|
||
extraProperties: {
|
||
'display': 'inline-block',
|
||
'vertical-align': 'middle',
|
||
},
|
||
}),
|
||
// 支持css class属性化
|
||
presetAttributify(),
|
||
// TODO: check 是否会有别的影响
|
||
// 处理低端安卓机的样式问题
|
||
// 将颜色函数 (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,
|
||
],
|
||
transformers: [
|
||
// 启用指令功能:主要用于支持 @apply、@screen 和 theme() 等 CSS 指令
|
||
transformerDirectives(),
|
||
// 启用 () 分组功能
|
||
// 支持css class组合,eg: `<div class="hover:(bg-gray-400 font-medium) font-(light mono)">测试 unocss</div>`
|
||
transformerVariantGroup(),
|
||
],
|
||
shortcuts: [
|
||
{
|
||
center: 'flex justify-center items-center',
|
||
},
|
||
],
|
||
// 动态图标需要在这里配置,或者写在vue页面中注释掉
|
||
safelist: ['i-carbon-code', 'i-carbon-home', 'i-carbon-user'],
|
||
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)' }],
|
||
],
|
||
theme: {
|
||
colors: {
|
||
/** 主题色,用法如: text-primary */
|
||
primary: 'var(--wot-color-theme,#0957DE)',
|
||
},
|
||
fontSize: {
|
||
/** 提供更小号的字体,用法如:text-2xs */
|
||
'2xs': ['20rpx', '28rpx'],
|
||
'3xs': ['18rpx', '26rpx'],
|
||
},
|
||
},
|
||
content: {
|
||
/**
|
||
* 解决小程序报错 `./app.wxss(78:2814): unexpected unexpected at pos 5198`
|
||
* 为什么同时使用include和exclude?虽然看起来多余,但同时配置两者是一种常见的 `防御性编程` 做法。
|
||
1. 结构变化保障 : 如果未来项目结构发生变化,某些排除目录可能被移动到包含路径下,exclude配置可以确保它们仍被排除
|
||
2. 明确性 : 明确列出要排除的目录使配置意图更加清晰
|
||
3. 性能优化 : 避免处理不必要的文件,提高构建性能
|
||
4. 防止冲突 : 排除第三方库和构建输出目录,避免潜在的CSS冲突
|
||
*/
|
||
pipeline: {
|
||
exclude: [
|
||
'node_modules/**/*',
|
||
'public/**/*',
|
||
'dist/**/*',
|
||
],
|
||
include: [
|
||
'./src/**/*',
|
||
],
|
||
},
|
||
},
|
||
})
|