Skip to content

Commit 787bf26

Browse files
doc: update README with v4 class name upgrade instructions
Co-authored-by: Mike Dalessio <[email protected]>
1 parent 4bf3e49 commit 787bf26

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

README.md

+63-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
- [Upgrading your application from Tailwind v3 to v4](#upgrading-your-application-from-tailwind-v3-to-v4)
1313
* [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade)
1414
* [Upgrade steps](#upgrade-steps)
15+
* [Post Upgrade](#post-upgrade)
1516
* [Troubleshooting](#troubleshooting)
17+
* [Updating CSS class names for v4](#updating-css-class-names-for-v4)
1618
- [Developing with Tailwindcss](#developing-with-tailwindcss)
1719
* [Configuration and commands](#configuration-and-commands)
1820
* [Building for production](#building-for-production)
@@ -91,12 +93,41 @@ gem "tailwindcss-ruby", "~> 3.4"
9193

9294
First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4.
9395

94-
``` html
96+
97+
```html
9598
# Gemfile
9699
gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4
97100
```
98101

99-
Then, run the `tailwindcss:upgrade` task. Among other things, this will try to run the official Tailwind upgrade utility. It requires `npx` in order to run, but it's a one-time operation and is *highly recommended* for a successful upgrade.
102+
If you want to migrate class names for v4 (optional), apply this [step](#upgrading-class-names-for-v4) and continue this guide.
103+
104+
Add the following line to the `.gitignore` file:
105+
106+
```gitignore
107+
/node_modules
108+
```
109+
(So the Tailwind update tool won’t dig through your node_modules files and infer incorrect migrations, because it complies with ``.gitignore`` constraints)
110+
111+
Then create a ``package.json`` in the root of the project:
112+
113+
```jsonc
114+
{
115+
"name": "app_name",
116+
"version": "1.0.0",
117+
"dependencies": {
118+
"tailwindcss": "^3.4.17", // Mandatory!!
119+
// Install all plugins and modules that are referenced in tailwind.config.js
120+
"@tailwindcss/aspect-ratio": "^0.4.2",
121+
"@tailwindcss/container-queries": "^0.1.1",
122+
"@tailwindcss/forms": "^0.5.10",
123+
"@tailwindcss/typography": "^0.5.16"
124+
// And so on...
125+
}
126+
}
127+
```
128+
**Run** ``npm install`` (or ``yarn install`` if using ``yarn``)
129+
130+
Then, **run** the `tailwindcss:upgrade` task. Among other things, this will try to run the official Tailwind upgrade utility. It requires `npx` in order to run, but it's a one-time operation and is *highly recommended* for a successful upgrade.
100131

101132
Here's what the upgrade task does:
102133

@@ -145,9 +176,13 @@ $ bin/rails tailwindcss:upgrade
145176
Done in 56ms
146177
run bundle install --quiet
147178
```
148-
149179
</details>
150180
181+
182+
### Post Upgrade
183+
184+
185+
151186
If this doesn't succeed, it's likely that you've customized your Tailwind configuration and you'll need to do some work to make sure your application upgrades. Please read the [official upgrade guide](https://tailwindcss.com/docs/upgrade-guide)!
152187
153188
@@ -157,12 +192,36 @@ You may want to check out [TailwindCSS v4 - upgrade experience report · rails/t
157192
158193
We know there are some cases we haven't addressed with the upgrade task:
159194
160-
- If the user isn’t using PostCSS, some migrations (e.g., updating class names in the view files) may fail
161195
- In setups without JavaScript tooling, the update process may fail to fully migrate `tailwind.config.js` because the tool assumes that the imported packages (e.g., tailwind plugins) are installed via a package manager, allowing them to be called.
162196
163197
We'll try to improve the upgrade process over time, but for now you may need to do some manual work to upgrade.
164198
165199
200+
### Updating CSS class names for v4
201+
202+
Before running the upgrade task, go to ``config/tailwind.config.js`` update the ``content`` part to:
203+
204+
```js
205+
content: [
206+
'../public/*.html',
207+
'../app/helpers/**/*.rb',
208+
'../app/javascript/**/*.js',
209+
'../app/views/**/*.{erb,haml,html,slim}'
210+
],
211+
```
212+
(Just add an additional ``.`` to all the paths referenced)
213+
214+
Run the upstream upgrader as instructed above.
215+
216+
Then, once you've run that successfully:
217+
218+
- **Delete** ``package.json``, ``node_modules/`` and ``package-lock.json`` (or ``yarn.lock``), plus remove ``/node_modules`` from ``.gitignore``.
219+
- **Go** to your CSS file and remove the following line (if present):
220+
```css
221+
@plugin '@tailwindcss/container-queries';
222+
```
223+
224+
166225
## Developing with Tailwindcss
167226
168227
### Configuration and commands

0 commit comments

Comments
 (0)