iTranslated by AI
A Tale of Struggles with Parcel + TailwindCSS (+ Simpacker)
Note
I got so stuck while working on this that I lost track of what was what,
so the following description might contain some misunderstandings 😭
TL;DR
- The status of Parcel + PostCSS 8 is not very good.
- The "PostCSS 8 for end users" guide says to use Parcel 2 (parcel@nightly).
- https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
-
parcel-plugin-bundle-manifest, which is required for simpacker, does not support Parcel 2 (parcel@next / parcel@nightly). - Parcel + postcss-import does not work well.
- Parcel 2 + postcss-import is fine.
- Conclusion: You need to downgrade related packages to the PostCSS 7 compatible state and then run
yarn parcel buildwith Parcel + TailwindCSS without using postcss-import.- Repository where I implemented this:
- https://github.com/JUNKI555/rails_erb_practice02
Origin
This issue occurred when I tried to add TailwindCSS + PostCSS to the environment I created in my previous article, "Creating a Rails6 + Simpacker + Parcel environment with rails new under docker-compose."
- Creating a Rails6 + Simpacker + Parcel environment with rails new under docker-compose | Junya Kitayama | zenn
root:/app# yarn parcel build --out-dir public/packs --public-url /packs app/assets/stylesheets/**.css
yarn run v1.22.5
🚨 /app/app/assets/stylesheets/application.css:undefined:undefined: PostCSS plugin tailwindcss requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
It's not working 😇
I had been stuck with this error before, so I initially thought it was something similar.
- Nov 2020 Version: Building a TailwindCSS + PostCSS development environment with yarn | Junya Kitayama | zenn
Parcel + PostCSS 8 is not in a very good state. But...
PostCSS 8 for end users says to use Parcel 2 (parcel@nightly):
- PostCSS 8 for end users | postcss / postcss | GitHub
However, parcel-plugin-bundle-manifest, which is required for simpacker in this environment, hasn't been updated in 2 years and does not support Parcel 2 (parcel@next / parcel@nightly).
- mugi-uno / parcel-plugin-bundle-manifest | GitHub
I want to switch to Parcel 2 but I can't 😇
Parcel + postcss-import doesn't work well
For details, please refer to the last comment in the ISSUE below, but it also says that since it's fixed in Parcel 2, you should use Parcel 2.
But I can't switch 😇
- Not working when using "postcss-import" with "postcss-next" | parcel-bundler / parcel | GitHub ISSUE
- "The css import problem (#1165) is already fixed in Parcel 2"
- https://github.com/parcel-bundler/parcel/issues/329#issuecomment-575991107
Solution: Revert related packages to PostCSS 7 compatible versions and run yarn parcel build using TailwindCSS without postcss-import
Since parcel-plugin-bundle-manifest itself isn't such a large plugin,
I could have written a plugin that works with Parcel 2 myself
and switched to Parcel 2,
but this time my heart was already starting to break,
so I decided to revert the related packages to their PostCSS 7 compatible versions...
The final package.json looks like this:
"devDependencies": {
"parcel-bundler": "^1.12.4",
"parcel-plugin-bundle-manifest": "^0.2.0",
"postcss": "^8.1.10",
"postcss-cli": "^8.3.0",
"postcss-modules": "^3.2.2",
"postcss-nested": "^4.2.3",
"tailwindcss": "^1.8.12"
}
postcss and postcss-cli are kept as they are since they support both 8 and 7.
Actually, I feel like I could even remove them... (I'm losing the energy to check anymore).
For other packages, I reverted them to versions before PostCSS 8 support while checking the Releases for each package.
Also, regarding css-import, I saw a comment in the following ISSUE saying
"If you want to use Parcel + TailwindCSS, do it without using css-import!",
so I decided to follow that.
- postcss-import does not compile CSS #1049
- "Found a counterintuitive/weird fix for this while working with Parcel."
- "Don't include postcss-import in your package, use @tailwind for tailwind, and @import for custom files" https://github.com/tailwindlabs/tailwindcss/issues/1049#issuecomment-675467853
So I removed css-import, and the .postcssrc prepared for Parcel became the following:
.postcssrc
{
"modules": true,
"plugins": {
"tailwindcss": {},
"postcss-nested": {}
}
}
- css | Parcel
Then, prepare the CSS to bring in TailwindCSS...
app/assets/stylesheets/tailwindcss.css
@tailwind base;
@tailwind components;
@tailwind utilities;
Now, let's try to build.
root:/app# yarn parcel build --out-dir public/packs --public-url /packs app/assets/stylesheets/**.css
yarn run v1.22.5
⠹ Building tailwindcss.css...
✨ Built in 103.98s.
public/packs/tailwindcss.css ⚠️ 1.73 MB 99.11s
public/packs/tailwindcss.css.map 558.54 KB 342ms
📦 PackageManifestPlugin
✓ bundle : tailwindcss.css => /packs/tailwindcss.css
📄 manifest : /app/public/packs/parcel-manifest.json
🖊 update manifest file
Done in 113.24s.
public/packs/tailwindcss.css
/* ! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height: ...(omitted below)
public/packs/parcel-manifest.json
{
"tailwindcss.css": "/packs/tailwindcss.css"
}
It's done! That's a relief.
By the way, if you're going to use the full TailwindCSS, you could just pull it from a CDN, but I was planning on customizing it later, so please forgive the fact that the example above looks like it should just use a CDN.
The steps taken this time are included in the following repository.
Sigh, this is really tough...
It's also said that Parcel gets difficult once you start introducing TypeScript,
so if you're using Simpacker, it might be better to just go with webpack honestly.
It makes me want to try going without a module bundler... (whisper)
References:
- Parcel v2
- Parcel v1
Discussion