-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework extraction to support nested atRules
This is closer to my webpack plugin and simplifies adding new features. Furthermore I've moved the combine logic into an own plugin to move it completely out of this repo in v2 to support more use cases.
- Loading branch information
Showing
4 changed files
with
116 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* TODO: move this into own repo for more use cases | ||
*/ | ||
|
||
const postcss = require('postcss'); | ||
|
||
module.exports = postcss.plugin('postcss-combine-media-query', opts => { | ||
|
||
const atRules = {}; | ||
|
||
function addToAtRules(atRule) { | ||
const key = atRule.params; | ||
|
||
if (!atRules[key]) { | ||
atRules[key] = postcss.atRule({ name: atRule.name, params: atRule.params }); | ||
} | ||
atRule.nodes.forEach(node => { | ||
atRules[key].append(node.clone()); | ||
}); | ||
|
||
atRule.remove(); | ||
} | ||
|
||
return (root) => { | ||
|
||
root.walkAtRules('media', atRule => { | ||
addToAtRules(atRule); | ||
}); | ||
|
||
Object.keys(atRules).forEach(key => { | ||
root.append(atRules[key]); | ||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters