Postcss Global Data config #12846
Replies: 4 comments
-
|
@Small-Systems I also struggled a bit on this. There's no need to configure/import anything inside Here's the config I came up with:
module.exports = {
plugins: {
'@csstools/postcss-global-data': {
files: [
'./assets/css/media.css',
]
},
'postcss-custom-media': {},
}
}
@custom-media --small (max-width: 400px);
@custom-media --medium (min-width: 401px) and (max-width: 800px);
@custom-media --large (min-width: 801px) and (max-width: 1200px);Example css code: @media (--small) {
body {
background-color: yellow;
font-size: 10px;
}
}
@media (--medium) {
body {
background-color: orange;
font-size: 15px;
}
}
@media (--large) {
body {
background-color: magenta;
font-size: 20px;
}
}This will make all these custom media definitions globally available for any css code that goes through PostCSS. An important detail that is somewhat buried in postcss docs is that the config above needs to list postcss-global-data BEFORE the others, otherwise this won't work as intended. Hope it helps, |
Beta Was this translation helpful? Give feedback.
-
|
Hi, Thanks for the information. I just can't this to work. The postcss-global-data will just not load files. I really don't get it... |
Beta Was this translation helpful? Give feedback.
-
|
I had to remove css: {
postcss: {
plugins: [
postcssGlobalData({
files: ['./custom-media-queries.css'],
}),
tailwindcss,
],
},
}, |
Beta Was this translation helpful? Give feedback.
-
|
The following configuration worked for me in my |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I setup the Postcss Global Data plugin in my vite.config.js file? I've tried the following but it doesn't work.
Beta Was this translation helpful? Give feedback.
All reactions