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

PostCSS plugins adapter #427

Closed
3 tasks
DenisIzmaylov opened this issue Feb 18, 2017 · 21 comments
Closed
3 tasks

PostCSS plugins adapter #427

DenisIzmaylov opened this issue Feb 18, 2017 · 21 comments
Labels
idea What if we turn JSS into styled-components?

Comments

@DenisIzmaylov
Copy link
Contributor

DenisIzmaylov commented Feb 18, 2017

Requirements:

  • Set of plugins for automating a kind of regular tasks, e.g. RTL, Browser Prefixes and so on.

Problems:

  • It takes a lot of time and effort to achieve it.

Solutions:

It would be great to have an adapter which make it possible to re-use PostCSS plugins in JSS and to get the existing ecosystem available without any changes.

Some examples:

  1. Autoprefixer: https://github.com/postcss/autoprefixer/blob/master/lib/autoprefixer.coffee
  2. RTL, which is discussing in [jss-rtl] Plugin for transforming to Right-To-Left (RTL) #410

The problem is that guys from PostCSS made a big vendor lock-in by using require("postcss") instead of dependency injection pattern.

@iamstarkov
Copy link
Member

@DenisIzmaylov wanna explore options and contribute?

@iamstarkov
Copy link
Member

do you need rtl? and jss has plugin for autoprefixing

@kof
Copy link
Member

kof commented Feb 20, 2017

PostCSS produces the AST, currently JSS doesn't have one.

@kof
Copy link
Member

kof commented Feb 20, 2017

I will wait with this until there is a specific case. From my experience 95% of things people need are already in place.

@kof
Copy link
Member

kof commented Feb 20, 2017

I will close this for now, because the output is not clear and overhead + work amount to make this happen is big. This would require a whole new concept.

@kof kof closed this as completed Feb 20, 2017
@kof kof added the idea What if we turn JSS into styled-components? label Feb 20, 2017
@kof
Copy link
Member

kof commented Feb 20, 2017

Also you don't need all postcss plugins in jss, those 2 have partially very different goals. Only some plugins are really useful.

@DenisIzmaylov
Copy link
Contributor Author

DenisIzmaylov commented Feb 20, 2017

Thanks for attention.

There is a lot of sugar and "nice to have" plugins which could be ported to JSS.

Almost all of those plugins could be used "AS IS".

Bonus point:

I think we have to define rule:

  • Do not close the issue until the author is answering
  • Issue could be closed in 48 hours if the author do not provide any answers

Or something like that.

@kof
Copy link
Member

kof commented Feb 20, 2017

We can always continue the discussion on a closed issue, closing means only that there are currently no actions planned. If I wouldn't a discussion I would lock the conversation.

@kof
Copy link
Member

kof commented Feb 20, 2017

For e.g. we have jss-vendor-prefixer for prefixing values and we have javascript to use any color library we want, I am using this one, postcss-write-svg and postcss-inline-svg don't make any sense, we can use string template or even import svg as a string.

@kof
Copy link
Member

kof commented Feb 20, 2017

Big differences between jss and postcss are:

  1. JSS is designed to work at runtime in the first place, on the server second.
  2. JSS tries a more functional API from the user standpoint, its not a new language. We try to use javascript features to produce CSS. PostCSS tries to enhance the CSS as a language, like babel. Lots of postcss plugins don't make any sense in JSS, especially syntactic sugar plugins.

@DenisIzmaylov
Copy link
Contributor Author

DenisIzmaylov commented Feb 21, 2017

Thank you for sharing your point. But in the same time it seems we have to think and to care about new users which could migrate from PostCSS, styled-components and so on.

In other words we should help to reduce any costs for this migration. It means any migration process should be smooth, step-by-step, etc. Otherwise it will be very expensive for the project budget and reduce JSS users. But by increasing the users is important goals. It we'll improve the quality. A lot of solutions are dead just by the one reason - they did not have a right promotion.

So it would be great if:

  • We will not limit anybody.
  • We will provide opportunities for end-users.
  • We will cover as much use cases as it possible.
  • We will add any "killer features" which could increase users base.
  • All activities in GitHub Issues will be more kind-friendly, predictable, expected and polite.
  • We will extend requirements - if someone do not use SSR it doesn't mean that SSR is something not important. It's actually really important for a wide range of commercial products. I've already explained that in my talks. I meant runtime and server side should be important both.

Sorry, if I understood something incorrect.

@kof
Copy link
Member

kof commented Feb 21, 2017

Thank you for sharing your point. But in the same time it seems we have to think and to care about new users which could migrate from PostCSS, styled-components and so on.

It will mean: rewrite and learn how to do those things in cssinjs. It doesn't mean they can run a magical script and migrate everything easily.

We will not limit anybody.

Constraints are the reason why one lib is a good fit for a particular task. If you have any specific things you want to add, feel free to create a separate issue for a very specific idea.

All activities in GitHub Issues will be more kind-friendly, predictable, expected and polite.

Does this mean my wording is not polite?

Thanks for your feedback, its mostly correct, but very philosophical. The only thing I can tell is that supporting all PostCSS plugins is a very hard task, which will require a complete rewrite. Also I act almost always upon specific feature request. Otherwise it ends up being useless, because we have no one to validate the quality of what we would do.

@kof
Copy link
Member

kof commented Feb 21, 2017

Btw. I someone REALLY wants postcss in jss at runtime, I could write a plugin, which will use the original postcss + allow to use any plugin. But the performance cost would be big + much bigger library size. I would do it or help doing it once at least 1 person has a valid use case to do so and asks.

@iamstarkov
Copy link
Member

@DenisIzmaylov here we go https://github.com/lttb/babel-plugin-prejss

@iamstarkov
Copy link
Member

dropmic

@kof
Copy link
Member

kof commented Feb 21, 2017

Its only for preprocessing, but yet it gives you everything from postcss.

@kof
Copy link
Member

kof commented Feb 21, 2017

Means one can't regenerate the styles created on the server differently, for e.g. if postcss rtl plugin has been used, you can't switch back to ltr at runtime, like it would be with a native jss plugin, but yet I guess it might be useful.

@DenisIzmaylov
Copy link
Contributor Author

@iamstarkov commented 9 hours ago:
DenisIzmaylov here we go https://github.com/lttb/babel-plugin-prejss

Yep! I've asked Artur to publish it yesterday. :)

On previous week we've started to make jss-from-css adapter which has been originally based on styled-components:

We used stylis.js like styled-components for preparing plain CSS from SCSS. For transforming plain CSS to JSS we used reworkcss. It's isomorphic and now you can use it as:

npm install jss-from-css --save-dev

There was one problem - performance issues on client-side because we have to parse CSS.

To solve it we create the task about babel plugin:

It was good news from Artur yesterday.

Now, when we solved performance issue on client-side transformation, we focused on PostCSS version to keep it integrated on both sides with prejss:

It means this PostCSS adapter and prejss babel plugin could be used together to keep the application code isomorphic:

  • On client-side PostCSS styles are converting to JSS by babel-plugin-prejss
  • On server-side PostCSS styles are converting to JSS by jss-from-postcss

@kof
Copy link
Member

kof commented Feb 22, 2017

On client-side PostCSS styles are converting to JSS by babel-plugin-prejss

This happens also on the server during the build, no?

@DenisIzmaylov
Copy link
Contributor Author

DenisIzmaylov commented Feb 22, 2017

With using babel plugin - yes - it's happening on server side during build stage. In this case on client-side we'll get a compiled callback function in final bundle which returns a plain JSS object.

On the server side we have this compilation on module execution stage (when a module is requiring).

This solution should be total replacement for styled-components. Or we missed something which still is good in SC and do not present in JSS?

@kof
Copy link
Member

kof commented Feb 22, 2017

Further discussions reg. styled-components api here: #341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea What if we turn JSS into styled-components?
Projects
None yet
Development

No branches or pull requests

3 participants