Skip to content

Commit

Permalink
[update]optimize combine preset
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderXL committed Dec 23, 2024
1 parent e238722 commit dc6373f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions packages/unocss-base/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { presetUno } from '@unocss/preset-uno'
import presetRn from './rn.js'

// eslint-disable-next-line
const remRE = /(-?[\.\d]+)rem/g

// todo process.env.MPX_CURRENT_TARGET_MODE
export default function presetMpx (options = {}) {
const uno = presetUno(options)
const { baseFontSize = 37.5 } = options
const mpxCurrentTargetMode = process.env.MPX_CURRENT_TARGET_MODE
const isReact = mpxCurrentTargetMode === 'ios' || mpxCurrentTargetMode === 'android'
const extraPresets = []
if (isReact) {
extraPresets.push(presetRn())
}

return {
...uno,
name: '@mpxjs/unocss-base',
Expand All @@ -18,11 +25,12 @@ export default function presetMpx (options = {}) {
util.entries.forEach((i) => {
const value = i[1]
if (typeof value === 'string' && remRE.test(value)) {
i[1] = value.replace(remRE, (_, p1) => process.env.MPX_CURRENT_TARGET_MODE === 'web'
i[1] = value.replace(remRE, (_, p1) => mpxCurrentTargetMode === 'web'
? `${p1 * baseFontSize * (100 / 750).toFixed(8)}vw`
: `${p1 * baseFontSize}rpx`)
}
})
}
},
presets: extraPresets
}
}
2 changes: 1 addition & 1 deletion packages/unocss-base/lib/rn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import presetRn from '../preset-rn/index.js'

export default function presetRnMpx (options = {}) {
export default function presetRnMpx () {
return {
name: '@mpxjs/unocss-preset-rn',
...presetRn,
Expand Down

0 comments on commit dc6373f

Please sign in to comment.