Skip to content

Commit

Permalink
fix(postcss): 小程序单位转换问题修复 fix #10752
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Dec 3, 2021
1 parent 92cc1b6 commit c8a6c71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions packages/postcss-pxtransform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
options = Object.assign(DEFAULT_WEAPP_OPTIONS, options || {})

switch (options.platform) {
case 'weapp': {
options.rootValue = 1 / options.deviceRatio[options.designWidth]
targetUnit = 'rpx'
break
}
case 'h5': {
options.rootValue = baseFontSize * options.designWidth / 640
targetUnit = 'rem'
Expand All @@ -59,6 +54,16 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options) {
targetUnit = 'px'
break
}
case 'quickapp': {
options.rootValue = 1
targetUnit = 'px'
break
}
default: {
// mini-program
options.rootValue = 1 / options.deviceRatio[options.designWidth]
targetUnit = 'rpx'
}
}

convertLegacyOptions(options)
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-mini-runner/src/webpack/postcss.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultPxtransformOption: {
} = {
enable: true,
config: {
platform: 'weapp'
platform: process.env.TARO_ENV
}
}

Expand Down

0 comments on commit c8a6c71

Please sign in to comment.