-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix conflict between CSS modules and postcss-custom-properties * Fix bad layout on iOS Safari 9 * Fix postcss-single-root plugin * Minor tweaks
- Loading branch information
1 parent
4b2bf59
commit 43cdfe8
Showing
7 changed files
with
68 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
/* eslint-disable global-require, import/no-extraneous-dependencies */ | ||
module.exports = { | ||
plugins: { | ||
autoprefixer: {}, | ||
"postcss-custom-properties": { | ||
plugins: [ | ||
require('autoprefixer'), | ||
require('postcss-custom-properties')({ | ||
preserve: true, // Preserve the original CSS variable declaration | ||
warnings: false, // Ignore warnings about variables declared on non-:root selectors | ||
} | ||
} | ||
}), | ||
// Custom plugin used to remove extra ':root' rules | ||
require('./scripts/postcss-single-root'), | ||
], | ||
}; |
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,41 @@ | ||
/** | ||
* A custom PostCSS plugin that strips away extra :root declarations | ||
* | ||
* We need this for postcss-custom-properties plugin and CSS modules | ||
* to work together properly, the ':root' CSS variable declaration | ||
* block need to be duplicated at the top of every CSS module's styles. | ||
* | ||
* This leads to a huge number of ':root' styles being emitted, which | ||
* isn't a huge problem in production since gzip can compress duplicate | ||
* text blocks for free, but does make development harder, so we strip | ||
* the extra ':root' rules using a PostCSS plugin. | ||
*/ | ||
|
||
const postcss = require('postcss'); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
const rootSelectors = [':root', 'body.mode-dark']; | ||
|
||
module.exports = postcss.plugin('postcss-single-root', () => (css) => { | ||
let isMainCSS = false; | ||
|
||
css.walkComments((comment) => { | ||
// Because PostCSS is run before css-loader, this plugin will receive a new | ||
// CSS object for every CSS module. This means that it needs to identify | ||
// which is the 'main.scss' file which it can then ignore so that it won't | ||
// drop the rules from the 'real' css-variables.scss file | ||
if (comment.text.includes('@postcss-single-root-entry')) { | ||
isMainCSS = true; | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
if (isMainCSS) return; | ||
|
||
css.walkRules((rule) => { | ||
if (rootSelectors.includes(rule.selector)) { | ||
rule.remove(); | ||
} | ||
}); | ||
}); |
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
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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
@import 'mixins'; | ||
@import 'functions'; | ||
@import 'css-variables'; |