Comments (5)
Here is my way to find bug and how to fix it.
I download the source and copy them to my project, then add some log to debug it .
what I found is, the file path in Declaration(decl) and Once(css) is NOT same sometimes.
there is my code
module.exports = (options = {}) => {
convertLegacyOptions(options);
const opts = Object.assign({}, defaults, options);
const satisfyPropList = createPropListMatcher(opts.propList);
const exclude = opts.exclude;
let isExcludeFile = false;
let pathOnec;
let pxReplace;
return {
postcssPlugin: "postcss-pxtorem",
Once(css) {
const filePath = css.source.input.file;
pathOnec = filePath;
if (
exclude &&
((type.isFunction(exclude) && exclude(filePath)) ||
(type.isString(exclude) && filePath.indexOf(exclude) !== -1) ||
filePath.match(exclude) !== null)
) {
isExcludeFile = true;
} else {
isExcludeFile = false;
}
const rootValue =
typeof opts.rootValue === "function"
? opts.rootValue(css.source.input)
: opts.rootValue;
pxReplace = createPxReplace(
rootValue,
opts.unitPrecision,
opts.minPixelValue
);
},
Declaration(decl) {
if (isExcludeFile) return;
console.log(` $$$$$$$ step2: Declaration(decl) ${decl.source.input.file}`);
console.log(` $$$$$$$ step2.1: pathOnec is ${pathOnec === decl.source.input.file ? 'same': `different: ${pathOnec}`}`);
if (
decl.value.indexOf("px") === -1 ||
!satisfyPropList(decl.prop) ||
blacklistedSelector(opts.selectorBlackList, decl.parent.selector)
)
return;
const value = decl.value.replace(pxRegex, pxReplace);
// if rem unit already exists, do not add or replace
if (declarationExists(decl.parent, decl.prop, value)) return;
if (opts.replace) {
decl.value = value;
} else {
decl.cloneAfter({ value: value });
}
},
AtRule(atRule) {
if (isExcludeFile) return;
if (opts.mediaQuery && atRule.name === "media") {
if (atRule.params.indexOf("px") === -1) return;
atRule.params = atRule.params.replace(pxRegex, pxReplace);
}
}
};
};
there is part of my full log
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is same
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:top :70px
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:padding :0 24px
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:width :1872px
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
>>>>>>>>>>>>2 decl.prop:height :64px
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2: Declaration(decl) C:/Users/glodon/repo/bimface-ops-bid/src/views/analysis/index.vue?vue&type=style&index=0&scoped=true&lang.less
$$$$$$$ step2.1: pathOnec is different: C:/Users/glodon/repo/bimface-ops-bid/src/webAppView/detailsEnergy.vue?vue&type=style&index=0&scoped=true&lang.less
After reading the documentation of postcss, I know postcss NEVER ensure that Declaration(decl) and Once(css) always in sync
from postcss-pxtorem.
Take version fallback to 5.1.1 ๐
from postcss-pxtorem.
hi, so is there any way to solve this problem ?
from postcss-pxtorem.
hi, so is there any way to solve this problem ?
I fix it in my PR #102, which has NOT been merged
you can use my forked npm withnpm i postcss-pxtorem-eric
from postcss-pxtorem.
hi, so is there any way to solve this problem ?
I fix it in my PR #102, which has NOT been merged
you can use my forked npm withnpm i postcss-pxtorem-eric
Here is still a problem in your solution
The problem in 6.0.0 is applying incorrect rootValue to target file
In your solution, some files not in exclude can be skipped too
from postcss-pxtorem.
Related Issues (20)
- "rootvalue" In the case of two designs, only one parameter can be set HOT 1
- [Bug Report: 6.0] Nested components and views may cause rootValue miscalculated (root in Once Event and decl in Declaration Event may be different) HOT 1
- **้ๅนดๆฅ้่ฎฟ้็บฆ
- How to configure Echarts to take effect?
- Can d.ts be provided to support vite2 + typescript?
- how to use it in rollup , with antd / antd-mobile integrated ? HOT 2
- Transform within default variables HOT 4
- When converting negative numbers, the number 0 needs to take units HOT 6
- The rootvalue function is not valid HOT 4
- It doesn't work when react-scripts's version is higher than or equal to 5.0.0 HOT 2
- problem in vite: isExcludeFile may not be correctly set HOT 6
- Feature request: support at-rules `@supports` and `@container` HOT 2
- some errors when px converts to rem HOT 10
- A little problem with the README.md file
- convert grid-area: 1/1/1/2 into grid-area๏ผ0.5
- Some errors happen when set exclude value to function: Range out of order in character class In regex. HOT 1
- is there a way to excluding CSS variable when transfrom px to rem๏ผ HOT 1
- (Help) Creating postcss.config.js in the root directory causes an error. HOT 2
- rootValue, How many settings are appropriate? is there a formula? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postcss-pxtorem.