# PostCSS 8.0 is coming: Here's what it brings

> Leaner node_modules, faster builds with the visitor API, dropping Babel for development, and more—thanks to your support

- Date: 2020-04-06T00:00:00.000Z
- Authors: Andrey Sitnik
- Categories: 
- URL: https://evilmartians.com/chronicles/postcss-8-is-coming-here-is-what-it-brings

---

PostCSS 8.0 now has its [dedicated branch](https://github.com/postcss/postcss/tree/ose) in the project repo. In keeping up with the tradition, the name of the new major release comes from [medieval demon lore](https://en.wikipedia.org/wiki/The_Lesser_Key_of_Solomon): President [Ose](https://en.wikipedia.org/wiki/Ose_(demon)). Andrey Sitnik, the framework's creator, unveils the upcoming changes that are now officially in the works thanks to the strong support from the open source community.

[PostCSS](https://postcss.org), the framework for processing CSS with JavaScript that [I started building while working at Evil Martians](https://evilmartians.com/chronicles/five-years-of-postcss-state-of-the-union), has been around since 2013. With 100+ million downloads a month, it quietly tops the charts of most popular frontend tools. It is harder to find frontend code that does _not_ rely on it in one way or another, many thanks to the ecosystem of [plugins](https://www.postcss.parts) that the community has been building for years.

*Read also Evil Martians' article*: https://evilmartians.com/chronicles/five-years-of-postcss-state-of-the-union

Since last year, PostCSS is transparently funded through [Open Collective](https://opencollective.com/postcss/), and we have felt some strong love from the community: from regular individual contributions to sizable one-time donations from our colleagues at [Tailwind CSS](https://tailwindcss.com/) and [De Voorhoede](https://www.voorhoede.nl/en/).

[Browserlist](https://github.com/browserslist/browserslist), PostCSS' close kin, is also funded through [Open Collective](https://opencollective.com/browserslist).

*Image: Current PostCSS backers ❤️*

The message that came with [De Voorhoede](https://www.voorhoede.nl/en/)'s donation says it all:

Many of our projects rely on PostCSS. It has a big impact, but receives little funding. We hope more will follow :)

## The API for the AST

PostCSS is a tool for transforming styles with JavaScript plugins. PostCSS takes a CSS file and provides an API to analyze and modify its rules (by transforming them into an Abstract Syntax Tree). This API is then used by the plugins to do many useful things:

* PostCSS is used by [Webpack](https://webpack.js.org/) to process CSS.
* [Autoprefixer](https://github.com/postcss/autoprefixer) uses PostCSS to insert vendor prefixes like `-webkit-user-select: none`.
* [Stylelint](https://stylelint.io/) finds common mistakes in CSS source.
* [`postcss-preset-env`](https://preset-env.cssdb.org/) polyfills new CSS syntax for old browsers.
* [PreCSS](https://github.com/csstools/precss) creates non-standard syntax sugar for better styles readability.

*Image: PostCSS sees more downloads than webpack, Babel, or node-sass*

Many big companies use PostCSS-based tools in their work, including [Facebook](https://engineering.fb.com/open-source/improving-css-quality-at-facebook-and-beyond/), [GitHub](https://github.com/primer/css/blob/main/postcss.config.cjs), and [Wikipedia](https://github.com/wikimedia/portals/blob/396dbe45dacdd4864dd5e43dbe90e48fe34e59a9/docs/architecture/css.md). Any project created with [Create React App](https://github.com/facebook/create-react-app/blob/d2f813f8897ffcd2f0b0d2da75d0c44924c92f4d/packages/react-scripts/package.json#L64-L68), [Angular CLI](https://github.com/angular/angular-cli/blob/7a224ec6a1f78207f0b3c03e50c91685156f46ff/packages/angular_devkit/build_angular/package.json#L43-L45), [Vue CLI](https://github.com/vuejs/vue-cli/blob/357c99a3fb6be4a9e15bc9b4266533b1ae477642/docs/guide/css.md), or even simple `rails new` uses PostCSS under the hood.

## What's new in PostCSS 8.0?

The current major version of PostCSS, [7.0](https://github.com/postcss/postcss/releases/tag/7.0.0), was released almost two years ago.

The new release will try to avoid breaking changes for most users. Plugins created for PostCSS 7.0 will work for PostCSS 8.0 as well.

PostCSS 8.0 will bring new API for plugins, which will make your CSS build faster and keep your `node_modules` smaller.

### Smaller node_modules

Now, every plugin has PostCSS in its `dependencies`. It may cause a problem of having multiple copies of PostCSS in your `node_modules`:

```shell
node_modules/
  autoprefixer/
    node_modules/
      postcss/       ← duplicate
  stylelint/
    node_modules/
      postcss/       ← duplicate
  postcss-normalize/
    node_modules/
      postcss/       ← duplicate
```

PostCSS 8.0 will make sure you have just a single PostCSS instance in `node_modules`.

### Faster CSS build

The most significant feature of PostCSS 8.0 will be a [visitor](https://en.wikipedia.org/wiki/Visitor_pattern) API for plugins. PostCSS is the parser, which parses the CSS to an object tree (AST). Then plugins change this tree. In the end, PostCSS generates a new CSS string from a modified object tree.

Currently, every PostCSS plugin walks through this tree. Often a plugin is looking just for a few properties, but it still needs to scan the whole tree. If you have many plugins in your build tool (or you use one plugin preset with many plugins inside, like `postcss-preset-env` or `stylelint`), most of the processing time will be spent in plugins walking through the tree again and again.

```js
// walkDecls walks through the whole tree to find all declaration nodes
root.walkDecls(decl => {
  if (decl.prop === 'will-change') {
    decl.cloneBefore({ prop: 'backface-visibility', value: 'hidden' })
  }
})
```

PostCSS 8.0 will include the optional API to subscribe only to select nodes. When all plugins subscribe to nodes, PostCSS will perform a single tree scan and call plugin's listener only on necessary nodes. It should increase performance in build tools that use multiple PostCSS plugins.

```js
// Callback for PostCSS single tree scan
root.on('decl', decl => {
  if (decl.prop === 'will-change') {
    decl.cloneBefore({ prop: 'backface-visibility', value: 'hidden' })
  }
})
```
Old API will neither be removed nor deprecated. It still works very well for experiments or for build chains that rely on less plugins.

### Project maintenance

In PostCSS 8.0, we are removing support for Node.js versions 6 and 8, as they have [stopped](https://nodejs.org/en/about/releases/) receiving security updates.

Also, we have removed Babel or any build step from the PostCSS core development process. We will publish ES2016 sources to npm. Since developers run PostCSS on the servers, it will not affect old browsers. CSS generated by PostCSS 8.0 will still work in old browsers (if you do not rely on new CSS syntax in your final production code, of course).

Removing the build step allows us to test new versions and bugfixes _before_ releasing them to npm, by installing PostCSS directly from our GitHub repository.

```json
  "devDependencies": {
    "postcss": "postcss/postcss"
  }
```

### New websites

The current version of the [PostCSS website](https://postcss.org/) is built with React. It was fun to build, but sending 800 KB of JS for a static website is not OK.

Recently, we ran a [successful experiment](https://evilmartians.com/chronicles/new-home-for-logux-pouring-love-into-an-oss-documentation-website) with the React-free approach to online documentation with a new [website for Logux](https://logux.org/), our new open source project. With just _4 KB of JS_, we got five times better _Time to Interactive_ and twenty times smaller _First Input Delay_, as well as a perfect score of 100 on Lighthouse.

*Read also Evil Martians' article*: https://evilmartians.com/chronicles/new-home-for-logux-pouring-love-into-an-oss-documentation-website

*Image: PostCSS website*

We are going to use these learnings to develop a new version of [postcss.org](https://postcss.org/).

---

Over the next few months, we will update the core, write up comprehensive migration guides, and update many plugins in the PostCSS ecosystem.

If your company uses PostCSS, think about joining Tailwind CSS and others in [supporting](https://opencollective.com/postcss/) our open source team behind the project, so we can keep working on improving your build tools.

If you are looking for a commercial advice on custom PostCSS integrations, or just looking at setting up better development practices at your team, feel free to [contact](https://evilmartians.com/contact-us) Evil Martians.

---

This article was written by [Evil Martians](https://evilmartians.com), a product development consultancy trusted by teams from early-stage startups to public companies. If you're working through a hard problem, [we can help](https://evilmartians.com/contact-us)
