-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathpostcss.config.js
More file actions
38 lines (34 loc) · 1.09 KB
/
postcss.config.js
File metadata and controls
38 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const rootClass = '.wedocs-document';
const escapedRoot = rootClass.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
const rootDescendantPattern = new RegExp(
escapedRoot + '\\s+:is\\(', 'g'
);
/**
* PostCSS plugin: For each Tailwind rule scoped as `.wedocs-document :is(.utility)`,
* add a matching selector `:is(.wedocs-document.utility)` so utilities also apply
* when the element itself is the root `.wedocs-document` container.
*/
const scopedRootMatch = () => ( {
postcssPlugin: 'wedocs-important-root-match',
Rule( rule ) {
if ( ! rootDescendantPattern.test( rule.selector ) ) {
return;
}
rootDescendantPattern.lastIndex = 0;
const rootSelector = rule.selector.replace(
rootDescendantPattern,
':is(' + rootClass
);
if ( rootSelector !== rule.selector ) {
rule.selector = rule.selector + ', ' + rootSelector;
}
},
} );
scopedRootMatch.postcss = true;
module.exports = {
plugins: [
require( 'tailwindcss' ),
require( 'autoprefixer' ),
scopedRootMatch,
]
}