MoOx / postcss-cssnext

`postcss-cssnext` has been deprecated in favor of `postcss-preset-env`.
https://moox.io/blog/deprecating-cssnext/
MIT License
5.3k stars 188 forks source link

Evaluate postcss-extend for inclusion #189

Closed travco closed 6 years ago

travco commented 9 years ago

postcss-extend

Developed to conform to the extend spec by Tab Atkins

'TLDR' primary points of contention:

MoOx commented 9 years ago

If @tabatkins has 1 min or 2, I would be very happy to have his opinion on this.

travco commented 9 years ago

I'll put this here so it doesn't need to be repeated...


tabatkins commented on May 4 in postcss#321:

@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. ...


travco commented 9 years ago

I think tabatkins may be understandably busy to drop in on this one @MoOx.

MoOx commented 9 years ago

Probably, like I am :) Meanwhile, you can use it via the cssnext plugins option.

stevenvachon commented 8 years ago

@tabatkins yo... save us.

tabatkins commented 8 years ago

@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.

MoOx commented 8 years ago

@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?

perrin4869 commented 8 years ago

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?

travco commented 8 years ago

@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.

tabatkins commented 8 years ago

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.

travco commented 8 years ago

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:

TLDR- Implementation is 'safe' and representative of per-spec browser behavior if the user follows directions and doesn't ignore warnings.

Shyam-Chen commented 8 years ago
.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;
}
Shyam-Chen commented 8 years ago

https://github.com/johnotander/css-extend

jonathantneal commented 7 years ago

Where are we at with travco/postcss-extend? Is this still in evaluation?

MoOx commented 7 years ago

From what I know, it won't be a safe transformation. But if some people want to dig deeper, please share your investigations here.

MoOx commented 6 years ago

postcss-cssnext has been deprecated in favor of postcss-preset-env. Read more at https://moox.io/blog/deprecating-cssnext/