Purgecss: Update postcss to 8.x

Created on 28 Sep 2020  路  16Comments  路  Source: FullHuman/purgecss

Not sure how hard this will be, but I didn't find a similar issue. Note that most projects moved postcss to a peer dependency.

enhancement

Most helpful comment

@ikornienko I published a new version with @next tag that contains this change. I'll let you know when it's part of a non-beta release.
e.g.

npm i -D purgecss@next

All 16 comments

Laravel Mix is moving to Postcss 8 in the next major version, which is giving some compatibility issues in https://github.com/spatie/laravel-mix-purgecss.

@sebastiandedeyne, what compatibility issue are you seeing? I understood that PostCSS 7 plugins would also work with PostCSS 8.
On another note, I started to look into PostCSS8, and I'll aim to release a version in the next couple of weeks.

I'm gonna dive back into this later this week, but to my understanding there wasn't really a problem with Purgecss being compatible with PostCSS 8, but a dependency issue.

Laravel Mix 8 requires PostCSS 8, while postcss-purgecss requires PostCSS 7. This causes two separate PostCSS versions to be installed, throwing weird dependency errors.

Yeah, with the release of PostCSS 8 it's now recommended that postcss plugins list PostCSS as a peer dependency instead of a direct dependency.

We just updated Tailwind to PostCSS 8 and using the current version of PurgeCSS that still uses PostCSS 7 has not been a problem at all for what it鈥檚 worth. PostCSS 8 is designed to work fine alongside other installations of PostCSS 7. You get a slightly annoying console warning about using a deprecated API but it works 馃憤馃徎

Interesting, I suppose the error was cause by something else. Gonna give this another try next week!

Update: when PurgeCSS is installed, it forces my test project to use PostCSS 7 over 8, which triggers an error on other packages that already require PostCSS 8.

ERROR  Failed to compile with 1 errors                                                                                     12:26:27 PM

error  in ./resources/css/app.css

Error: PostCSS plugin autoprefixer requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users

That said, if I explicitly define a yarn resolution, the build passes without any issues, and everything gets purged correctly. So I can report that PurgeCSS runs on PostCSS 8 without any issues. (at least for my small test file)

"resolutions": {
  "postcss": "8.1.2"
}

@sebastiandedeyne Can you share a test project? Curious what would cause that. Mix should be requiring PostCSS 8 as a dependency itself, so it should use the correct version otherwise npm/yarn have a bug which doesn't sound likely for super basic require stuff 馃

Sure! You can check out this branch: https://github.com/spatie/laravel-mix-purgecss/pull/90

In the repo, cd example, yarn, and yarn production to build. If you remove resolutions from package.json and start over, it will fail.

@sebastiandedeyne Looks like just running yarn add postcss in that folder also fixes it. Not sure the best solution there, things are definitely a little weird now that PostCSS 8 is always supposed to be installed as a peerDependency.

We have to update all of the Tailwind installation instructions for example to npm install tailwindcss postcss now :/

@sebastiandedeyne Looks like you should be doing that actually, installing postcss explicitly is now part of the instructions for installing postcss-loader:

image

We have this issue with Laravel Mix too. The most prevalent version of PostCSS gets hoisted so postcss-loader gets postcss 7 but Laravel Mix gets postcss 8 when requiring. I'm investigating adding postcss directly to the root package json after the user installs mix to get around it.

@thecrypticace I think best solution for Mix is to just include postcss in the default Laravel webpack.mix.js file. For people installing Mix separately, you should just make the installation instructions npm install laravel-mix postcss (grim I know but it's simple and will solve the problem).

Is it fully resolved now with https://github.com/FullHuman/purgecss/commit/beb4a5913c5508a88053aa77926b9db9354013ee? Can anyone give a hint when a new version with that change will be released?

@ikornienko I published a new version with @next tag that contains this change. I'll let you know when it's part of a non-beta release.
e.g.

npm i -D purgecss@next

The PostCSS plugin has been updated to use PostCSS 8 and has dropped support to PostCSS 7 with version 4.0+.
If using PostCSS 7, postcss-purgecss 3.0 should be used instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joneldiablo picture joneldiablo  路  6Comments

Pab89 picture Pab89  路  8Comments

eldiegod picture eldiegod  路  4Comments

simplenotezy picture simplenotezy  路  3Comments

spaceemotion picture spaceemotion  路  4Comments