-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"exclude" will NOT work SOMETIMES when there are tons of files in project #101
Comments
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. 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
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 😑 |
|
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 |
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.
The text was updated successfully, but these errors were encountered: