-
-
Notifications
You must be signed in to change notification settings - Fork 188
Should custom properties be ignored when not scoped to :root? #186
Comments
You just want to get rid of the warnings right? |
That sounds like it'll work. At some point I might be able to submit a PR for a way to expose custom
|
To expose (keep) custom props, you can use the following option: {
features: {
customProperties: {
preserve: true
}
}
} With that in mind, will you be happy if we add an option in customProperties to hide warnings (like |
Sure, sounds fantastic.
|
If you install and reinstall cssnext, you should get the new version of postcss-custom-properties (4.2.0) that include the |
What is the reason for this warning? Say for example I have the following
with the following markup:
This warning is thrown:
Is it ok to use variables this way? Is it ok to just disable warnings in this case? |
Never mind. The readme has the answer:
These warnings are emitted because postcss can't backfill compatibility only by modifying the css files. Postcss doesn't know that |
Hi, The warnings: false option works but is not documented anywhere. Just a heads up. |
Hi @Aiky30, I'm using webpack and I've tried so many solution without success. Here is my actual setup: module: {
rules: [
test: /\.(scss|sass|css)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
ident: 'postcss',
plugins: (loader) => [
customProperties({ warnings: false }),
mqpacker({ sort: sortCSSmq }),
cssnext(),
cssnano({ safe: true })
]
}
}
]
})
}
]
} |
@jimblue It looks like you'll need to set the warnings property as a config for cssnext. My snippet of that module is below:
I'm using webpack v2. I hope that helps. In your setup I'd probably do:
|
@Aiky30 tks it's working 😄 ! |
@Aiky30 about using css-loader option that already use cssnano under the hood. I found two benefit from declare cssnano in postcss:
What's your point on this, maybe I'm wrong... |
Just started playing around with cssnext, and I immediately got this error when testing out what happened when I assigned something a custom property:
So I see what this is about. Custom properties, when used for
var()
, want to be placed inside:root
so that they're globally available. Butvar()
isn't the only reason why you might want to use custom properties.I haven't seen a lot of people connecting the dots and talking about this, but custom properties are incredibly useful for writing web components. Here's a situation I ran into a few days ago:
<pie-chart percent="33"></pie-chart>
This is a custom element that extends
<canvas>
, and will draw a pie chart to itself based on the value of thepercent
attribute. The thing is, the JS to do this needs to be passed two different colors: the color of the empty section of the pie chart, and the color of the full section. I wanted to be able to do this with CSS. I was left with having to use the various color properties in non-standard ways. For example, I'd render the canvas with something like:and then
But that creates a problem of giving the entire canvas a gray background instead of rendering everything surrounding the pie chart transparent. So instead, I had to use:
Thankfully, I didn't also need to render my pie chart with a CSS outline, so this variable was otherwise unused. Also the color variable, because there was no text. But that's a lucky situation, and this is still a hack using CSS properties in a non-standard way. What I'd really like to be able to do is:
Unfortunately, cssnext isn't equipped to handle that kind of situation. I don't know if this sort of behavior is outside the scope of cssnext, vis-a-vis exposing custom properties to JS for this kind of purpose, but it's something that I think a lot of people will be increasingly exploring as web components become more popular. So it's a question I'd at least like to discuss.
The text was updated successfully, but these errors were encountered: