-
Notifications
You must be signed in to change notification settings - Fork 345
Add postcss.config.js
/.browserslistrc
configs
#2881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
postcss.config.js
and .browserslistrc
postcss.config.js
and .browserslistrc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you see the investigation I did into which plugins were actually doing something we needed?
I think we can probably get rid of calc
, unroot
, unnth
and potentially unnot
as when I last tested they weren't doing anything.
We might also actually need postcss-unmq
– although we have unmq: { disable: true }
in the config, it's using the wrong namespace so that bit of the config isn't actually doing anything 🙃
Generally it'd be good to compare the built dist
and package
folders with and without this change to see what effect it has.
I did indeed, was very useful (stuck it in the description!) This PR was more of a like-for-like "as is" spike, just to see if it was possible Shall I add the |
Soon as I add
But the error comes from css-mediaquery (See issue: ericf/css-mediaquery#7) If we tap into their code and add some logging it's caused by: https://github.com/alphagov/govuk-frontend/blob/main/src/govuk/helpers/_device-pixels.scss#L33 {
expression: '(-o-min-device-pixel-ratio: 20 / 10)',
RE_MQ_EXPRESSION: /\(\s*([^\s\:\)]+)\s*(?:\:\s*([^\s\)]+))?\s*\)/,
captures: null
} ☝️ It was never expecting media queries to be formatted that way But why??The older Changes via
Just a hunch (similar to Babel), but I wonder if |
8ed2f98
to
5495a55
Compare
postcss.config.js
and .browserslistrc
postcss.config.js
/.browserslistrc
+ remove "oldie"
Solved it! Had another go at this during the Frontend Community meeting 😊 We were running the
But for the IE8 styles we guard with For our Browserslist config I've added a lonely new environment:
So this PR now introduces two "diffs" versus the previous CSS output:
Ready for review 👍 |
postcss.config.js
Outdated
const isIE8 = file.basename.includes('-ie8') | ||
|
||
const plugins = [ | ||
autoprefixer({ env: isIE8 ? 'oldie' : env }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual env
is "production" or "development" based on NODE_ENV
This is another one linked with #2243 |
5495a55
to
cf0e7ed
Compare
postcss.config.js
/.browserslistrc
+ remove "oldie"postcss.config.js
/.browserslistrc
Breaking changes moved to #2924 |
With the PostCSS configs separated out the Gulp task can be simplified too #2912 |
cf0e7ed
to
cb146a2
Compare
postcss.config.js
/.browserslistrc
postcss.config.js
/.browserslistrc
configs
postcss.config.js
Outdated
] | ||
|
||
// Minify CSS | ||
if (file.basename.endsWith('.min.css')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to tooling file extension differences (source vs target) this is now name.endsWith('.min')
postcss.config.js
Outdated
|
||
// Auto-generate 'companion' classes for pseudo-selector states - e.g. a | ||
// :hover class you can use to simulate the hover state in the review app | ||
if (file.basename.startsWith('app-')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original logic for this looks like it was "anything that's not the dist
folder".
I get the other two if
conditions, but for some reason I'm struggling to figure this change out, so I've probably missed something obvious - could you explain why this only applies to app-
files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no, I should've read the surrounding code - so this stuff is applied to:
app/assets/scss/app.scss
in compileStyles
app/assets/scss/app-legacy.scss
in compileLegacy
app/assets/scss/app-legacy-ie8.scss
in compileLegacyIE
.
So my revised query is why app.scss
isn't included in the if condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You beat me to it with your reply!
I started by spotting the companion classes added in three places:
When taking only !isDist
into account that gives us the filenames:
app.css
app-legacy.css
app-legacy-ie8.css
Strangely you'll see app-ie8.scss
was excluded (a bug?) so that's now fixed
BUT brilliant spot though. I'm going to push again to include app.css
🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed again due to a slight complication
- Plugin for Gulp
gulp-postcss
populates PostCSS ctx.file as typeimport('vinyl')
- Plugin for webpack
postcss-loader
populates PostCSS ctx.file as a file pathstring
Found this out using the webpack example #2869
Additionally the Gulp stream ctx.file.extname
will be .css but other tools pass the original .scss
Take a look at the new version 👍
Thanks @domoscargin
cb146a2
to
db0c833
Compare
db0c833
to
de8ec57
Compare
postcss.config.js
Outdated
} | ||
|
||
// Transpile CSS for Internet Explorer | ||
if (name.endsWith('-ie8')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is doing what we want when running npm run build:dist
because at that point we're generating a minified CSS file which ends with -ie8.min
, so this plugin doesn't get added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted, this was a well-intentioned change from yesterday (previously .includes()
) so I'll put it back!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. For clarity I've matched on both:
if (name.endsWith('-ie8') || name.endsWith('-ie8.min')) {
Plus I've added tests for each combination we rely on
Gulp’s `gulp-postcss` uses Vinyl file objects but webpack’s `postcss-loader` uses string files
de8ec57
to
c2b50c5
Compare
env = 'production' | ||
}) | ||
|
||
describe('Default', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice to have these tests 👍🏻
Just a suggestion, but there's quite a lot of repetition in the test structure – could be a good case for describe.each
using something like this?
const combinationsToTest = [
{
name: 'Default',
paths: ['example.css', 'example.scss'],
expectedPlugins: ['autoprefixer']
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @36degrees
Yeah I didn't optimise by choice, but can come back and improve these in future?
Take a look in #2924 (based on this branch) where we start to add in the environment switching tests for "Old IE"
[node] | ||
node 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have engines
in our package.json
– do we need both? Just seems like another thing to potentially get out of sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove engines
from package.json to be fair
They have different purposes:
-
.browserslistrc → Target environment
Tells our tooling what features are supported when building -
Package
engines
→ Development environment
Tells our local environment what versions are allowed for development
For example, when Node.js 18 LTS lands on the 25th October we'll likely want to increase our engines
ranges, update tests, GitHub workflows etc, so our contributors can use the latest supported Node.js version.
But for compatibility, any compiled code (Node.js or browser) should still adhere to our build target environments
This PR adds two new config files
postcss.config.js
and.browserslistrc
PostCSS config via
postcss.config.js
To make it simpler to configure our CSS output the following
postcss()
calls now share the same configBrowser config via
.browserslistrc
It's nice to have a separate shareable config which could also be used by Babel, Jest, ESLint, in future
Breaking changes have been moved into a second PR #2924