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

some errors when px converts to rem

Open spring011 opened this issue 3 years ago • 10 comments

Configure rootValue by function, There are some errors that px converts to rem. I use development environment:postcss-pxtotem v6.0.0, vite2.0+, vue3. At the same time,I use vue3 component library vant3.0+。to match the Vant style,I do as follow in file postcss.config.js:

const path = require('path');
module.exports = {
  plugins: {
    'postcss-pxtorem': {
      rootValue({ file }) {
        return file.indexOf('node_modules' + path.sep + 'vant') !== -1 ? 37.5 : 75;
      },
      // rootValue: 75,
      propList: ['*'],
      selectBlackList: ['.norem'],
    },
  },
};

Access the page in the browser,that is no problem. As shown in the figure below,browser got a index.6f88061b.css file that dose not refer to Vant component library。index.6f88061b.css file is about page logic and when make px converts to rem in this file the calculator uses rootValue 75. example, height of .top_tile class is 2.8rem.Everything is all right. ok

however, somtimes there are some errors when I access page browser.The page content becomes larger resulting in out-of-browser size.and browser got another css file named index.82969300.css not index.6f88061b.css. height of .top_tile class becomes twice the height.now the height is 5.6rem. error

spring011 avatar Sep 02 '22 08:09 spring011

Maybe you could add 'console.log(file)' inside the rootValue function to see the file path when error occurs ~

yuningjiang123 avatar Sep 20 '22 12:09 yuningjiang123

Maybe you could add 'console.log(file)' inside the rootValue function to see the file path when error occurs ~

when use console.log, the print is no problem.

spring011 avatar Sep 23 '22 08:09 spring011

try https://github.com/hemengke1997/postcss-pxtorem

hemengke1997 avatar Oct 11 '22 11:10 hemengke1997

I have the same problem. Have you solved it now?

1007875327 avatar Oct 15 '22 07:10 1007875327

I have the same problem. Have you solved it now?

I did

hemengke1997 avatar Oct 15 '22 07:10 hemengke1997

I solved this problem by reducing the version to 5.1.1

1007875327 avatar Oct 15 '22 09:10 1007875327

@hemengke1997 具体是什么原因导致的这个问题呢?

jiadesen avatar Jan 11 '23 07:01 jiadesen

@hemengke1997 具体是什么原因导致的这个问题呢?

这个库的hook调用有点儿问题,你可以试试我fork的库:https://github.com/hemengke1997/postcss-pxtorem

hemengke1997 avatar Jan 11 '23 07:01 hemengke1997

You can just downgrade to v5.1.1 and it'll be fine

mayuxian avatar Mar 02 '23 08:03 mayuxian

My scenario is converting px to rem, and sometimes it will be converted to rem under v6.0.0, and sometimes px will not be converted. Currently, the conversion output of v5.1.1 is very stable.

chenxch avatar Aug 25 '23 01:08 chenxch