A
A
Alexey Nikolaev2015-10-21 02:31:57
css
Alexey Nikolaev, 2015-10-21 02:31:57

What is the point of PostCSS today?

Goodnight.
PostCSS has recently started to become fashionable - there are many posts and articles about it. There is even a version (not without reason) that it is the progenitor of all modern preprocessors and trends. Okay, let's consider it so, especially since the history of commits on the Gita confirms this more likely.
But what does it give in general, what are the specific advantages of using it? So far, I have not found anything at all that would favorably expose PostCSS to established bundles of preprocessors. After all, everything that PostCSS can do can be done by preprocessors - just like all the features of Assembler are in C.
Why has PostCSS started to populate news feeds so actively? PR campaign, or something more? ..

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey, 2015-10-21
@Heian

PostCSS has recently started to become fashionable - there are many posts and articles about it.

And why not? Any tools need to be promoted so that people use them. For the people will use what they hear (well, or what they are used to working with). More people - more ideas, development goes faster, a community is formed and it becomes a little easier to support a solution. And it's nice when your work is used.
Where did you read this? postcss was an attempt to solve problems that can't be solved by preprocessors (or can take a long time).
What exactly confirms? first there was Sass written by rubists so that CSS could be prepared as gently as they prepare HTML on HAML (coffeescript there too, the rubists wanted to make js look like ruby). And this was noticed in 2006! then js was slow, and V8 was only in the plans ...
postcss does absolutely nothing out of the box. It can only load the AST CSS file and dazzle the same CSS back from it.
And that's where the strength of postcss is modularity. All existing preprocessors are monolithic. That is, you cannot just take and add something of your own there. Yes, in the latest versions of less (and it seems like sass is being pulled there as well) you have a primitive set of tools to wedge into the process of processing an AST document and add some primitive things. But it's not convenient. If you want to dynamically change properties (for example, recalculate rem to em) or add more (again, so that you don’t have to manually produce casts for different browsers in css and do it automatically, without tying into mixins and leaving CSS clean) properties, but doing it on less/sass is hard.
It is much easier to take postcss and set this business on the result of the work of preprocessors.
Let's come up with an example of what can be easily done with post processors and what is difficult to do with preprocessors. The very first thing that comes to mind is resource inlining. For example, small pngs. Or work with relative paths, resolving them more precisely. In this case, we will write a small function with postcss that will iterate through the entire abstract syntax tree and find the use of url(). then we can check the image dimensions and inline them (if they are small enough). Or collect a list of all involved images and use them later (for example, to copy only what we actually use).
Something like that. And due to the fact that we have access entirely to the formation and processing of AST, we can also develop the CSS syntax. Numerous plugins ala cssnext and so on can serve as examples. You can even connect most of the sass features in the form of plugins.
And the funny thing is that it works faster than the same libsass on the pluses. Due to the architecture (I mean not naked postcss, but with a set of plugins that add sass functionality).

M
malroc, 2015-10-21
@malroc

After all, everything that PostCSS can do, preprocessors can too

Well, just the opposite
Do you happen to have some special PostCSS of your own? Actually, version 0.1 was released there only in 2013, by that time SASS was already 6 (!) years old.

I
Ilya Erofeev, 2015-10-21
@imerofeev

I advise you to read another article: andrew-r.ru/notes/?go=all/why-postcss

A
Alexander Taratin, 2015-10-21
@Taraflex

Apart from https://github.com/postcss/autoprefixer there is not much that is useful in my opinion.

A
Alex Elgin, 2018-04-29
@sijio

  1. As already noted, the architecture of preprocessors is monolithic, i.e. you can only use the features provided by the preprocessor developer. PostCSS architecture is modular, PostCSS capabilities are extended by connecting plugins. Anyone can create a plugin, which then any arc can easily connect to their project. If you need some very special CSS handling that isn't in the set of published plugins , you can easily write your own plugin for that. Those. PostCSS will evolve faster with third party extensions to the plugin library.
  2. Due to the large number of plugins available, PostCSS already provides more options for processing CSS than, say, SASS.
  3. As input, preprocessors receive a CSS file template, which they form. This is where their work ends. PostCSS receives a CSS file as input, parses it into a style structure, which gives much more processing options. In addition, due to the precss plugin, PostCSS can do the same thing as the SASS preprocessor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question