Closed travco closed 6 years ago
If @tabatkins has 1 min or 2, I would be very happy to have his opinion on this.
I'll put this here so it doesn't need to be repeated...
@extend, as defined in the draft, cannot be emulated by a preprocessor. It's impossible, due to the way specificity works. @extend, as Sass does it, is slightly different - specificity is different, and it has to use a number of heuristics to limit the combinations it actually generates to those most likely to be useful. ...
I think tabatkins may be understandably busy to drop in on this one @MoOx.
Probably, like I am :)
Meanwhile, you can use it via the cssnext plugins
option.
@tabatkins yo... save us.
@travco's quote from me is correct - @extend
, as defined in the spec, cannot be done in preprocessor (just like var()
can't be done in a preprocessor), as it depends on live-page information/integration with the browser.
If you want to add @extend
to PostCSS, just copy what Sass has done, which is a decent approximation of a "proper" @extend
.
@travco I don't use extends so I am not the best person to choose if this is "safe" to add. For example custom props transformation is limited to root to make a "safe but incomplete" transformation, that should work the same in browsers when they will implement custom props. Can we say the same of you extend plugin, or will the result can change when the transformation of your plugin will be handled by a browser?
Sorry if this question is stupid, but at first glance I can't see the difference between @extend
and @apply
... what are the different use-cases?
@perrin4869 @apply
operates very similar to var()
except it can hold sets of declarations instead of values (as per it's spec). In addition, custom sets of properties you reference in an @apply
overwrite each-other if you redefine them.
@extend
allows you to take another rule's declarations as a template, and if needed modify/replace them in specificity. As well as extend other things that are (themselves) extending, and use sub-classes of the extended thing. As a result you can 'pull' from multiple sources with only a single line, with expectable results.
TLDR- They're both fruit for your syntactic sugar. If you need fruit, either -can- (more or less) perform the same task but @apply
has a more restricted rule set and would require many more lines to do the same thing.
Right. They can both achieve the same simple cases, but each has more complex cases that are specific to them. This is mostly due to how they move information from opposite sides - @apply
gets set up by the outer page and pushed into components, @extend
is the component pulling styles in without the outer page having to do anything or even know it's occurring.
that should work the same in browsers when they will implement custom props. Can we say the same of you extend plugin, or will the result can change when the transformation of your plugin will be handled by a browser?
@MoOx Sorry for missing an opportunity to reply, all of the features included in postcss-extend at current fall into one of two categories:
@media
tags - where only what can by done by the preprocessor is done, and what can't isn't.TLDR- Implementation is 'safe' and representative of per-spec browser behavior if the user follows directions and doesn't ignore warnings.
.foo {
color: red;
}
.bar {
@extend .foo;
background: green;
}
.baz {
@extend .bar;
padding: 1rem;
}
:root {
--foo: {
color: red;
};
}
.foo {
@apply --foo;
}
.bar {
@apply --foo;
background: green;
}
.baz {
@apply --foo;
background: green; // need to write again
padding: 1rem;
}
Where are we at with travco/postcss-extend? Is this still in evaluation?
From what I know, it won't be a safe transformation. But if some people want to dig deeper, please share your investigations here.
postcss-cssnext
has been deprecated in favor of postcss-preset-env
. Read more at https://moox.io/blog/deprecating-cssnext/
postcss-extend
Developed to conform to the extend spec by Tab Atkins
'TLDR' primary points of contention:
@define-placeholder
and it's aliases for compatibility with simple-extend, and the%
placeholder from the spec. As this isn't the native parser, the placeholder will be wiped from the CSS if it goes unused (as well as throw a warning).:active
)@extend
rule.