Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocess future-proof CSS features #130

Closed
giuseppeg opened this issue Jul 23, 2016 · 63 comments
Closed

Preprocess future-proof CSS features #130

giuseppeg opened this issue Jul 23, 2016 · 63 comments

Comments

@giuseppeg
Copy link

Would you be open to add a few future-proof PostCSS plugins to transpile things like custom properties, calc, custom media queries?

This could be as simple as using the postcss-cssnext plugin or set up a lil preprocessor like we did for suitcss.

If there is interest I can probably help out.

@mxstbr
Copy link
Contributor

mxstbr commented Jul 23, 2016

There's an ongoing discussion about this in #78!

The TL;DR by @gaearon about cssnext is:

Whatever we add, it needs to be rock-stable. I’m worried about issue lists like this: https://github.com/postcss/postcss-import/issues.

@mxstbr mxstbr closed this as completed Jul 23, 2016
@giuseppeg
Copy link
Author

That one is a more broad topic since it is about adding support for SASS/Less.
What I was asking here is if there is any interest in transpiling future-proof features like we already do in JavaScript with Babel.

Regarding cssnext, yep I agree that "there’s a lot of stuff there" – if we want to play it safe we could just add imports, variables (custom properties), calc, custom-media and autoprefixer.

Anyway I am fine with waiting and see where #78 goes.

@gaearon
Copy link
Contributor

gaearon commented Jul 23, 2016

We are open to add transpilation for standardized features if those tools don't have large issue lists. We don't want to recommend broken tools by default.

@gaearon gaearon reopened this Sep 8, 2016
@gaearon gaearon added this to the 1.0.0 milestone Sep 8, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 8, 2016

Since #78 has gone a little bit too broad, let’s use this issue for specific proposals about PostCSS plugins that are safe to enable, work great, correspond to stable specs, and give at least some of the features people want.

@giuseppeg
Copy link
Author

Stable

TBD

N.B. the plugins below don't support dynamic custom properties i.e. cp are compiled to static values.

Personally I also use postcss-autoreset and Stylelint but those require custom configuration.

@MoOx
Copy link
Contributor

MoOx commented Sep 13, 2016

My 2 cents:

  • postcss-import "just" need a maintainer + revert to v7 (which was more stable than the current one).
  • I can handle a revert to postcss-import to v7 if that can be useful to a lot of people, should take a second.
  • postcss-easy-import use postcss-import v8, so forget this one imo.
  • postcss-cssnext does not includes postcss-import !
  • postcss ecosystem is not rock solid anyway (postcss-import is a proof, imo a core plugin, does not get any love from anybody - and I asked for help multiples times)
  • I can give access to some maintainers for a lot of postcss plugins I created (mostly all future proof syntax related plugins).

I am myself using CSS-in-JS (via RN-web) and avoid CSS when possible.

@glennreyes
Copy link
Contributor

glennreyes commented Sep 13, 2016

I'd love to see postcss-cssnext as it has autoprefixer and pretty rock solid and optional features baked in

@davidkpiano
Copy link

davidkpiano commented Sep 13, 2016

I would strongly advise to take caution with CSS custom properties, and if something like postcss-custom-properties were to be included, it would be a good idea to set: preserve: true (not computed) in order to maintain the spec behavior as closely as possible.

Here's a trivial example of a potential issue:

:root {
  --foo: green;
}

header {
  --foo: red;
}

h1 {
  color: var(--foo);
}

What color is <h1>? Answer: it depends. It's 🍏 by default, but when it's in a <header>, it is 🔴, because custom properties cascade and inherit. Here's another fantastic example of that behavior: http://lea.verou.me/2016/09/autoprefixing-with-css-variables

Keep in mind: all major browsers (except IE and Edge, where it is in progress) support CSS Custom Properties.

@ai
Copy link
Contributor

ai commented Sep 13, 2016

I like this feature: https://github.com/postcss/postcss-media-minmax

@media screen and (width >= 500px) and (width <= 1200px) {
  .bar {
    display: block;
  }
}

Polyfill is very stable. Spec is a official draft: https://drafts.csswg.org/mediaqueries/#mq-range-context

Feature is pretty useful, because it is always hard to work with min-/max- stuff instead of >=/<=.

@ai
Copy link
Contributor

ai commented Sep 13, 2016

will-change polyfill is very useful, but it is not so stable (will not work if you defined backface-visibility on same tag, but with different class). So it is open question, should we add it.

https://github.com/postcss/postcss-will-change

@ai
Copy link
Contributor

ai commented Sep 13, 2016

I think this plugin is mush-have: https://github.com/postcss/postcss-color-function

  1. It is very useful, color transformations are one of the most popular feature
  2. Spec is very stable
  3. Polyfill works without any problem (any lack of documentation)

@ai
Copy link
Contributor

ai commented Sep 13, 2016

:any-link is useful, stable and have no problems in polyfill: https://github.com/jonathantneal/postcss-pseudo-class-any-link

@ai
Copy link
Contributor

ai commented Sep 13, 2016

:matches is useful, stable and works well: https://github.com/postcss/postcss-selector-matches

@jquense
Copy link
Contributor

jquense commented Sep 13, 2016

Like me and @taion noted in #78, there are few that aren't/can't be to spec, or actively allow non-spec behavior. In particular the color() function is insiduously wrong, in that it doesn't distinguish between lightness(+10%) and lightness(+ 10%) (did you even notice the difference?) in the modifier functions. That whitespace should determine whether the change is absolute or relative, but it doesn't distinguish right now

@taion
Copy link

taion commented Sep 13, 2016

As @davidkpiano and @jquense note above, most of the more useful cssnext features have significant caveats.

  • Custom properties only polyfill the simple case where the property serves as a variable (with clunky syntax), and doesn't handle the new cases that the syntax actually allows
  • Color function does non-spec-compliant things around whitespace between modifier sign and modifier value
  • calc() polyfill only works if all units match
  • Nesting improperly allows Sass-like concatenative selectors: Concatenative selectors csstools/postcss-nesting#17

cssnext is very cool, but it's not like Babel in that the features it transpiles are transpiled in a manner that is close enough to spec compliant to "just work".

Some of the smaller polyfills in there might be nice, but the "big" ones have meaningful caveats attached.

@taion
Copy link

taion commented Sep 13, 2016

The capsule summary is that, for people not paying close attention to the actual spec, Babel loose mode is order of magnitudes safer than the majority of new features enabled by cssnext, and CRA isn't even using that: #198

@deathmood
Copy link

the only thing that I really would like to see are css variables. They are already available in chrome and firefox -- so it's like a working and already implemented thing. But it does not work in IE and Edge that is why we need to post process it.

so my vote goes for https://github.com/MadLittleMods/postcss-css-variables

@taion
Copy link

taion commented Sep 13, 2016

They're not variables, they're custom properties – and as the repo you mentioned notes, they can't be correctly polyfilled, so you end up with support for either an odd arbitrary subset, or non-spec-compliant behavior that you're actually likely to run into (unlike with Babel).

It's not at all a reasonable default.

@ai
Copy link
Contributor

ai commented Sep 13, 2016

@jquense could you please open a issue in postcss-color-function. Your example with space could be fixed and it is not fundamental problem of polyfill. What else color() issues do you have?

@ai
Copy link
Contributor

ai commented Sep 14, 2016

@MoOx

Not a single PostCSS plugin is rock solid

Relying on PostCSS is a very bad idea on many levels

each postcss plugins I know have tons of issues. All of them.

Using PostCSS for stuff like PreCSS is kind of stupid

I agree with you, that CSS specs are not so stable to have future-proof plugins (Custom Media removing change my mind), but don’t be so toxic about speaking of all PostCSS.

Autoprefixer is rock solid and no big knowing issue and using it is a great idea on any level ;).

CSS Modules works great too and definitely don’t have “tons of issues”

PostCSS is not only “cssnext” stuff. There are many other tools, which works great. And create-react-app already use some of this tools (Autoprefixer and css-loader).

Other great tool that could be implemented in zero-config app is a Stylelint — it has non-codestyle rules to avoid mistakes.

@MoOx
Copy link
Contributor

MoOx commented Sep 14, 2016

@ai My goal is not to be toxic, it's to be relevant to CRA requirements.
Sure Autoprefixer is rock solid (I had this one in mind when I said that some are probably fine). I didn't take this one into account since it's already built-in.
CSS-Modules is also very nice, but it's a "special" plugin, probably too opinionated, and you know it.
Stylelint is also not a classic PostCSS plugins too. I guess this one can be a good choice. But here we have a linter, not a preprocessor.

Obviously there is some good in PostCSS :)

Except Styelint with a small config (even the styelint-config-standard include stylistic rules) and Autoprefixer, I don't think something will be the right fit for CRA.

@giuseppeg
Copy link
Author

Should we use github's reactions to decide what to do about this issue?

I would suggest to use ±1 (thumb up/down) on this comment to decide if we want to:

  1. 👎 keep the status-quo and close this issue
  2. 👍 keep the status-quo but add the possibility to customize postcss via config file as described in my previous comment

cc @gaearon

@MoOx
Copy link
Contributor

MoOx commented Sep 14, 2016

No config, means no config. I am pretty sure nobody want to add config just to support the (not really mature) PostCSS ecosystem :/

@giuseppeg
Copy link
Author

giuseppeg commented Sep 14, 2016

@MoOx I don't have strong opinions, I just think that we shouldn't discuss if PostCSS is good|bad|stable|unstable forever :)

fwiw 2) would be an add-on only feature i.e. if you want to configure postcss you have a way to do so otherwise continue to do what you were doing :)

fwiw2 I also think that in the long run css-in-js will win so shurg

@ai
Copy link
Contributor

ai commented Sep 14, 2016

I agree that “no config” means no config”.

(not really mature) PostCSS ecosystem :/

@MoOx don’t be toxic. If cssnext plugins is not really mature, doesn’t mean that other plugins are not really mature. Stylelint, Autoprefixer, PostCSS Assets and CSS Modules show a great example of mature ecosystem.

It is especially painful to hear “not really mature” from your, because you a maintainer of cssnext, and esosystem problems in cssnext is on you. Don’t spread cssnext’s lack of maintaibility to other well maintained plugins.

@yordis
Copy link

yordis commented Sep 14, 2016

Let's find a solution that works for everybody

No config means no config

Well, then don't force the package to lookup something and have predefined PostCSS plugins that only are well maintained and curated.

Config, Hurrah!

Just add a parameter that is a Javascript file, arguments could be many things open to people who know more than me, where you could whatever Javascript allow you to do 😄
This way pretty much we cover the use case of advance users like me, who don't want to lose the flexibility of adding some stuff.

@giuseppeg I support both cases, 0 config and advance user, because I really dont want to lose the flexibility of adding some good stuff like @ai called, so

@ai
Copy link
Contributor

ai commented Sep 14, 2016

Anyway I think that we could close this issue. Main topic was about future-proof plugins. As was shown CSS specs are not so stable as ES2016 was in 2015, so plugins (even very well done with good support) could not be future-proof for zero-config case of CRA.

@yordis maybe you should open a separated issue about config.

@yordis
Copy link

yordis commented Sep 14, 2016

I would prefer @gaearon to open a new issue if need it. The core contributors have the final word on this.

@daviestar
Copy link

daviestar commented Sep 14, 2016

For design-led websites - which is a lot of websites, and what I make all day - unfortunately I can't use this amazing, maintained, JS build tool if it doesn't support SASS, or any kind of CSS betterer.

😔

If I could hook my own CSS (and other asset) build tools in with this somehow, and have the browser update with changes, I'd find a way to make it work.

@gaearon
Copy link
Contributor

gaearon commented Sep 23, 2016

For design-led websites - which is a lot of websites, and what I make all day - unfortunately I can't use this amazing, maintained, JS build tool if it doesn't support SASS, or any kind of CSS betterer.

If I could hook my own CSS (and other asset) build tools in with this somehow, and have the browser update with changes, I'd find a way to make it work.

It supports SASS in the exactly same way people have been using SASS for years. Run a console SASS watcher, and import the resulting CSS from your JS files.

@gaearon gaearon removed this from the 0.5.0 milestone Sep 23, 2016
@daviestar
Copy link

daviestar commented Sep 23, 2016

Thank you, I ended up using gulp to build all my non-js tasks.

For SASS, I compile to _styles.css at the project src root, import that css file at my JS root.. and update npm start to

npm-run-all <gulp task> <react scripts>

and everything works great.

@giuseppeg
Copy link
Author

@gaearon I feel like that we can close this issue unless you want to implement this thing

@tonyxiao
Copy link

@daviestar do you have one css file per component then? Or just a single massive _index.css file at project root?

@daviestar
Copy link

@tonyxiao I put SASS files in with my components, but as I said above I don't really agree I should import them into JS as IMO, CSS doesn't work that way. I can easily avoid it by compiling all my SASS files to one CSS file at the root using gulp, then just import that so webpack picks it up in development.

@tonyxiao
Copy link

Got it, thanks a pretty workable approach if you just completely avoid importing css into js. thanks for sharing @daviestar

@gaearon
Copy link
Contributor

gaearon commented Sep 30, 2016

Let’s close as there is no consensus and I don’t feel comfortable proceeding with this.

@jonathantneal
Copy link

That Sassy nesting has finally been fixed.

@MoOx
Copy link
Contributor

MoOx commented May 29, 2018

FYI, I deprecated cssnext in favor of postcss-preset-env, you might want to think about this one that offers stages like babel-preset-env!

@ai
Copy link
Contributor

ai commented May 29, 2018

Yeap. With postcss-preset-env we can enable only stable CSS specs. It has stage option same as in Babel.

@gaearon
Copy link
Contributor

gaearon commented Oct 2, 2018

We run postcss-preset-env now.

@jonathantneal
Copy link

I’d love to share this with my family and friends. I wrote PostCSS Preset Env, the tool you are using to future proof CSS. I hope it’s not presumptuous to ask, but might it earn a mention or thanks in the blog notes, @gaearon?

https://reactjs.org/blog/2018/10/01/create-react-app-v2.html

@gaearon
Copy link
Contributor

gaearon commented Oct 2, 2018

We should probably include it into the notes. I forgot.

@lock lock bot locked and limited conversation to collaborators Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests