Skip to content

Commit 315daf5

Browse files
authored
Merge pull request #1 from IvanKalinin/feature--increase-specificity
Feature increase specificity
2 parents 0840c80 + 2b582ad commit 315daf5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ It's useful when you, for instance, need to post process the CSS as a string.
104104
|**`camelCase`**|`{Boolean\|String}`|`false`|Export Classnames in CamelCase|
105105
|**`importLoaders`**|`{Number}`|`0`|Number of loaders applied before CSS loader|
106106
|**`localIdentName`**|`{String}`|`[hash:base64]`|Configure the generated ident|
107+
|**`increaseSpecificity`**|`{Object}`|`{}`|Enable/Disable and configure the postcss-increase-specificity plugin|
107108

108109
### `root`
109110

@@ -430,6 +431,31 @@ The query parameter `importLoaders` allows to configure how many loaders before
430431

431432
This may change in the future, when the module system (i. e. webpack) supports loader matching by origin.
432433

434+
### `increaseSpecificity`
435+
436+
The query parameter `increaseSpecificity` allows to enable and configure postcss-increase-specificity plugin. See [postcss-increase-specificity's documentation](https://github.com/MadLittleMods/postcss-increase-specificity/blob/master/README.md) for more information on the available options.
437+
438+
**webpack.config.js**
439+
```js
440+
{
441+
test: /\.s?css$/,
442+
use: [
443+
'style-loader',
444+
{
445+
loader: 'css-loader',
446+
options: {
447+
increaseSpecificity: {
448+
stackableRoot: '.my-root', // string - Selector that is repeated to make up the piece that is added to increase specificity
449+
repeat: 1, // number - The number of times we prepend options.stackableRoot in front of your selector
450+
},
451+
}
452+
},
453+
'postcss-loader',
454+
'sass-loader'
455+
]
456+
}
457+
```
458+
433459
<h2 align="center">Examples</h2>
434460

435461
### Assets

lib/processCss.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var modulesScope = require("postcss-modules-scope");
1616
var modulesValues = require("postcss-modules-values");
1717
var valueParser = require('postcss-value-parser');
1818

19+
var postcssIncreaseSpecificity = require('postcss-increase-specificity');
20+
1921
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
2022
return function(css) {
2123
var imports = {};
@@ -158,6 +160,8 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
158160
resolve: options.resolve
159161
};
160162

163+
var increaseSpecificity = query.increaseSpecificity || {};
164+
161165
var pipeline = postcss([
162166
modulesValues,
163167
localByDefault({
@@ -186,7 +190,12 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
186190
});
187191
}
188192
}),
189-
parserPlugin(parserOptions)
193+
parserPlugin(parserOptions),
194+
postcssIncreaseSpecificity({
195+
stackableRoot: increaseSpecificity.stackableRoot || '',
196+
repeat: increaseSpecificity.repeat || 1,
197+
overrideIds: increaseSpecificity.overrideIds || true,
198+
})
190199
]);
191200

192201
if(minimize) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lodash.camelcase": "^4.3.0",
2121
"object-assign": "^4.0.1",
2222
"postcss": "^5.0.6",
23+
"postcss-increase-specificity": "^0.5.0",
2324
"postcss-modules-extract-imports": "^1.0.0",
2425
"postcss-modules-local-by-default": "^1.0.1",
2526
"postcss-modules-scope": "^1.0.0",

0 commit comments

Comments
 (0)