"exclude" will NOT work SOMETIMES when there are tons of files in project
Opened this issue ยท 5 comments
background
my h5 page is in the same project when my web page, I only use pxtorem in my h5 page, exclude all my web page.
the bug
it works well in my localhost, but in the online environment which is build with jenkins, web page is using rem sometimes, not always.
After I rebuild on jenkins, it works well again.
It is hard to create a large project to reproduct this bug.
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
hi, so is there any way to solve this problem ?
Take version fallback to 5.1.1 ๐
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
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