Skip to content

Commit 70b190e

Browse files
authored
Pass in filename to transform callback (#97)
* Pass in filename to transform callback * Update README.md * fix small typo
1 parent b87905c commit 70b190e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ module: {
9999
plugins: {
100100
"postcss-prefix-selector": {
101101
prefix: '.my-prefix',
102-
transform(prefix, selector, prefixedSelector) {
102+
transform(prefix, selector, prefixedSelector, filepath) {
103103
if (selector.match(/^(html|body)/)) {
104104
return selector.replace(/^([^\s]*)/, `$1 ${prefix}`);
105105
}
106+
107+
if (filepath.match(/node_modules/)) {
108+
return selector; // Do not prefix styles imported from node_modules
109+
}
110+
106111
return prefixedSelector;
107112
},
108113
},

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ module.exports = function postcssPrefixSelector(options) {
4343
return options.transform(
4444
prefix,
4545
selector,
46-
prefixWithSpace + selector
46+
prefixWithSpace + selector,
47+
root.source.input.file
4748
);
4849
}
4950

0 commit comments

Comments
 (0)