postcss-pxtorem icon indicating copy to clipboard operation
postcss-pxtorem copied to clipboard

Wildcard propList not working

Open dnwhte opened this issue 7 years ago • 9 comments

I cannot seem to get the wildcard propList to work

dnwhte avatar Apr 25 '17 04:04 dnwhte

How are you using it? Could you provide your options and CSS?

cuth avatar Apr 25 '17 12:04 cuth

Same Problem here:

  minify: false,
  use: ['postcss-pxtorem', 'postcss-mixins', 'postcss-nested', 'postcss-for', 'postcss-calc'],
  stylelint: lint,
  autoprefixer: {
    browsers: ['ie >= 10', 'ie_mob >= 10', 'ff >= 30', 'chrome >= 34', 'safari >= 7', 'opera >= 23', 'ios >= 7', 'android >= 4.4', 'bb >= 10'],
    cascade: true
  },
  postcss: {
    map: true
  },
  pxtorem: {
    rootValue: 16,
    unitPrecision: 5,
    propList: ['*'],
    selectorBlackList: [],
    replace: true,
    mediaQuery: false,
    minPixelValue: 0
  }
};```

Only default options are converted.

henrikwirth avatar May 03 '17 11:05 henrikwirth

@henrikwirth, what version do you have installed?

cuth avatar May 03 '17 12:05 cuth

I was having the issue with the gulp version (https://github.com/cuth/gulp-pxtorem). Issue was not present when I switched to the postcss version.

dnwhte avatar May 03 '17 15:05 dnwhte

I am using version "postcss-pxtorem": "^3.3.1" and i'm having the same issue.

In fact, when i try putting just margin or padding in the array, they don't convert either.

"mediaQuery": false,
"propList": [
	"*"
],
"replace": false,
"rootValue": 18,
"selectorBlackList": [
	/^body$/,
	/^html$/
]

mikemak-es avatar May 05 '17 10:05 mikemak-es

@cuth "postcss-pxtorem": "^4.0.1"

henrikwirth avatar May 05 '17 10:05 henrikwirth

@michaelhwinter you'll need to use propWhiteList instead of propList. Here is the README for 3.3.1.

@henrikwirth Do you need to set the settings with 'postcss-pxtorem' instead of pxtorem?

cuth avatar May 05 '17 13:05 cuth

@cuth i tried that too, but it didn't change the result, still px where rems should be

mikemak-es avatar May 08 '17 10:05 mikemak-es

Here are my tests for wildcards:

  it("should only replace properties in the prop list", function() {
    var css =
      ".rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }";
    var expected =
      ".rule { font-size: 1rem; margin: 1rem; margin-left: 5px; padding: 5px; padding-right: 1rem }";
    var options = {
      propWhiteList: ["*font*", "margin*", "!margin-left", "*-right", "pad"]
    };
    var processed = postcss(pxtorem(options)).process(css).css;

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

  it("should only replace properties in the prop list with wildcard", function() {
    var css =
      ".rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }";
    var expected =
      ".rule { font-size: 16px; margin: 1rem; margin-left: 5px; padding: 5px; padding-right: 16px }";
    var options = {
      propWhiteList: ["*", "!margin-left", "!*padding*", "!font*"]
    };
    var processed = postcss(pxtorem(options)).process(css).css;

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

Can you provide a test that breaks?

cuth avatar Mar 04 '20 02:03 cuth