postcss-pxtransform 3.7.0-alpha.8 → 3.7.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +21 -12
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -40,7 +40,7 @@ let targetUnit
40
40
 
41
41
  module.exports = (options = {}) => {
42
42
  options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options)
43
-
43
+ const exclude = options.exclude
44
44
  const transUnits = ['px']
45
45
  const baseFontSize = options.baseFontSize || (options.minRootSize >= 1 ? options.minRootSize : 20)
46
46
  const designWidth = (input) =>
@@ -50,17 +50,22 @@ module.exports = (options = {}) => {
50
50
  case 'h5': {
51
51
  targetUnit = options.targetUnit ?? 'rem'
52
52
 
53
- if (targetUnit === 'vw') {
54
- options.rootValue = (input) => {
55
- return designWidth(input) / 100
56
- }
57
- } else if (targetUnit === 'px') {
58
- options.rootValue = (input) => (1 / options.deviceRatio[designWidth(input)]) * 2
59
- } else {
60
- // rem
61
- options.rootValue = (input) => {
62
- return (baseFontSize / options.deviceRatio[designWidth(input)]) * 2
63
- }
53
+ switch (targetUnit) {
54
+ case 'vw':
55
+ case 'vmin':
56
+ options.rootValue = (input) => {
57
+ return designWidth(input) / 100
58
+ }
59
+ break
60
+ case 'px':
61
+ options.rootValue = (input) => (1 / options.deviceRatio[designWidth(input)]) * 2
62
+ break
63
+ default:
64
+ // rem
65
+ options.rootValue = (input) => {
66
+ return (baseFontSize / options.deviceRatio[designWidth(input)]) * 2
67
+ }
68
+ break
64
69
  }
65
70
 
66
71
  transUnits.push('rpx')
@@ -116,6 +121,10 @@ module.exports = (options = {}) => {
116
121
 
117
122
  /** 是否跳过当前文件不处理 */
118
123
  let skip = false
124
+
125
+ if (exclude && exclude?.(result.opts.from)) {
126
+ return null
127
+ }
119
128
 
120
129
  return {
121
130
  // 注意:钩子在节点变动时会重新执行,Once,OnceExit只执行一次,https://github.com/NervJS/taro/issues/13238
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-pxtransform",
3
- "version": "3.7.0-alpha.8",
3
+ "version": "3.7.0-beta.3",
4
4
  "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/NervJS/taro/issues"
20
20
  },
21
- "homepage": "https://github.com/NervJS/taro#readme",
21
+ "homepage": "https://github.com/NervJS/taro/tree/next/packages/postcss-pxtransform#readme",
22
22
  "jest": {
23
23
  "testEnvironment": "node",
24
24
  "testEnvironmentOptions": {}