Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postcss): pxtransform baseFontSize 取值问题 #12460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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