Skip to content

Commit

Permalink
fix(postcss): pxtransform baseFontSize 取值问题
Browse files Browse the repository at this point in the history
  • Loading branch information
林纪莹 committed Sep 9, 2022
1 parent fecd894 commit 014851c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/postcss-pxtransform/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ describe('px2rem', function () {

expect(processed).toBe(expected)
})

it('8 should work on custom baseFontSize', function () {
const processed = postcss(px2rem({ platform: 'h5', baseFontSize: 15 })).process(basicCSS).css
const expected = '.rule { font-size: 0.5rem }'

expect(processed).toBe(expected)
})
})

describe('value parsing', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-pxtransform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) {
options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)

const transUnits = ['px']
const baseFontSize = options.baseFontSize || options.minRootSize >= 1 ? options.minRootSize : 20
const baseFontSize = options.baseFontSize || (options.minRootSize >= 1 ? options.minRootSize : 20)
const designWidth = input => typeof options.designWidth === 'function'
? options.designWidth(input)
: options.designWidth
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-webpack-runner/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function parseHtmlScript (pxtransformOption: IPostcssOption['pxtransform'
const options = pxtransformOption?.config || {}
const max = options?.maxRootSize ?? 40
const min = options?.minRootSize ?? 20
const baseFontSize = options?.baseFontSize || min > 1 ? min : 20
const baseFontSize = options?.baseFontSize || (min > 1 ? min : 20)
const designWidth = (input => typeof options.designWidth === 'function'
? options.designWidth(input)
: options.designWidth)(baseFontSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class H5WebpackPlugin {
const options = this.pxtransformOption?.config || {}
const max = options?.maxRootSize ?? 40
const min = options?.minRootSize ?? 20
const baseFontSize = options?.baseFontSize || min > 1 ? min : 20
const baseFontSize = options?.baseFontSize || (min > 1 ? min : 20)
const designWidth = (input => typeof options.designWidth === 'function'
? options.designWidth(input)
: options.designWidth)(baseFontSize)
Expand Down

0 comments on commit 014851c

Please sign in to comment.