Replies: 4 comments 8 replies
-
Hi @gpspake, thank you for starting this discussion! Can you take a look at this example : When I run The plugins seem to work well in a Webpack context : CSS : .a {
color: var(--color);
} props : :root {
--color: pink;
} Webpack config : const path = require('path');
const postcssGlobalData = require('@csstools/postcss-global-data');
module.exports = {
mode: 'production',
entry: './index.js',
target: 'node',
optimization: {
minimize: false,
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.cjs',
},
module: {
rules: [
// We document how to use our plugins together with Webpack.
// This test validates this documentation.
{
test: /\.css$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssGlobalData({
files: ['./props.css'],
}),
[
'postcss-preset-env',
{
stage: 0,
preserve: false,
},
],
],
},
},
},
],
},
],
},
}; Is there a difference with your setup that I am overlooking? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response @romainmenke 🙂 The css variables and the other css files they're used in are actually (mostly) in another library I'm importing which adds a layer of confusion. I'll try to dig in to my configuration some more and compare some things. |
Beta Was this translation helpful? Give feedback.
-
We have this legacy component/style library we use internally. Classic: It was written a while ago and we're migrating away from it but we need to support it a little longer. I think I'm starting to see that it's just organized a little unusually which might be why this is weird. The library is installed as an npm package but it doesn't have any build so the dist is just the whole source and the consuming app is responsible for building. It's a react component lib so, for example:
In
there are no explicit imports where the variables come from, instead, the library exports a variables js object which I mentioned in the first example... So:
I guess the original idea was that the variables could be reused but I think if it were just a css file (instead of a js object) and the file was imported in the local component css files, that might be the right way to fix this and everything might just work...
Assuming we want to skip that, though, avoid having to touch the external lib, and:
|
Beta Was this translation helpful? Give feedback.
-
Ok, @romainmenke - first of all, thanks so much for all the help!
Which should be...
When I migrated the js variables over to CSS, I replaced the commas with semicolons and didn't realize the font strings were affected too. As we've been working on this, the fonts in the UI have been our immediate indicator that our config wasn't working so it's likely this has been working the whole time 🤦 So there it is... still a good discussion, I think 🙂 |
Beta Was this translation helpful? Give feedback.
-
I'm using the
importFrom
option withpostcss-preset-env
to make css custom properties available globally.importFrom
is removed in the latest version and postcss-global-data seems to be the recommended alternative. I'm trying to update my configuration to use it but it's not working for me and I'm having a hard time finding docs and examples.Currently, all of my custom properties in a javascript file like this:
variables.js
And I import them in my config using
importFrom
like this:webpack.config.babel.js
That makes the custom properties available as fallbacks, basically so if any of them are used in our css, they get resolved correctly.
So how do I replace this set up with
postcss-global-data
? Here's what I've tried based on the postcss-global-data docsFirst I moved the custom properties in to a css file:
css-custom-properties.css
Then I changed my config to pass that file to
postcss-global-data
webpack.config.babel.js
I've also tried changing the plugin order in case that's the problem...
webpack.config.babel.js
Note: In case the path could be a factor, the css file is in the same directory as the webpack config. The file structure looks like this
Note: My IDE is showing this error which might be a clue. Maybe I'm misusing the plugin.
Other plugins aren't showing this error:
Beta Was this translation helpful? Give feedback.
All reactions