postcss-plugin-constparse 3.5.7-alpha.9 → 3.5.8

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 +10 -9
  2. package/package.json +3 -6
package/index.js CHANGED
@@ -1,27 +1,28 @@
1
+ const postcss = require('postcss')
2
+
3
+ module.exports = postcss.plugin('postcss-plugin-constparse', plugin)
4
+
1
5
  const PLATFORM = {
2
6
  WEAPP: 'weapp',
3
7
  H5: 'h5'
4
8
  }
5
9
 
6
- module.exports = (opts = {}) => {
10
+ function plugin (opts) {
7
11
  opts = Object.assign({
8
12
  constants: [{
9
13
  key: 'taro-tabbar-height',
10
14
  val: '50PX'
11
15
  }]
12
16
  }, opts)
13
-
14
- return {
15
- postcssPlugin: 'postcss-plugin-constparse',
16
- Declaration (decl) {
17
- if (opts.platform === PLATFORM.WEAPP) return
17
+ return function (root) {
18
+ // 在小程序下会忽略
19
+ if (opts.platform === PLATFORM.WEAPP) return
20
+ root.walkDecls(function (decl) {
18
21
  let value = decl.value
19
22
  opts.constants.forEach(item => {
20
23
  value = value.replace(new RegExp(item.key, 'g'), item.val)
21
24
  })
22
25
  decl.value = value
23
- }
26
+ })
24
27
  }
25
28
  }
26
-
27
- module.exports.postcss = true
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "postcss-plugin-constparse",
3
- "version": "3.5.7-alpha.9",
3
+ "version": "3.5.8",
4
4
  "description": "parse constants defined in config",
5
5
  "main": "index.js",
6
6
  "author": "Simba",
7
7
  "license": "MIT",
8
- "devDependencies": {
9
- "postcss": "^8.4.18"
10
- },
11
- "peerDependencies": {
12
- "postcss": "^8.4.18"
8
+ "dependencies": {
9
+ "postcss": "^6.0.22"
13
10
  }
14
11
  }