Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## About this fork version
This fork version is used to fix the issue: [https://github.com/cuth/postcss-pxtorem/issues/101#issuecomment-1774384284](https://github.com/cuth/postcss-pxtorem/issues/101)

As my PR is not merged for now so I create create this version



# postcss-pxtorem [![NPM version](https://badge.fury.io/js/postcss-pxtorem.svg)](http://badge.fury.io/js/postcss-pxtorem)

A plugin for [PostCSS](https://github.com/ai/postcss) that generates rem units from pixel units.
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ module.exports = (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)) ||
Expand All @@ -151,6 +153,13 @@ module.exports = (options = {}) => {
Declaration(decl) {
if (isExcludeFile) return;

/**
* fix: when there are tons of file,
* Declaration's file path will be NOT same with Once's file path,
* the excluded files with be convert from px to rem TOO
*/
if (decl.source.input.file !== pathOnec) return;

if (
decl.value.indexOf("px") === -1 ||
!satisfyPropList(decl.prop) ||
Expand Down
Loading