Skip to content

Commit ecdbdee

Browse files
authored
Merge pull request #485 from rails/flavorjones-prep-for-upgrade
Prep docs and post-install message for final v4.0.0 release
2 parents 738ba68 + 0cc3f19 commit ecdbdee

File tree

2 files changed

+79
-49
lines changed

2 files changed

+79
-49
lines changed

README.md

+65-49
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535

3636
## Installation
3737

38-
With Rails 7 you can generate a new application preconfigured with Tailwind by using `--css tailwind`. If you're adding Tailwind later, you need to:
38+
With Rails 7 you can generate a new application preconfigured with Tailwind CSS by using `--css tailwind`. If you're adding Tailwind later, you need to:
3939

4040
1. Run `./bin/bundle add tailwindcss-rails`
4141
2. Run `./bin/rails tailwindcss:install`
4242

43-
This gem depends on the `tailwindcss-ruby` gem to install a working tailwind executable.
43+
This gem depends on the `tailwindcss-ruby` gem to install a working Tailwind CLI executable.
4444

4545

4646
### Choosing a specific version of `tailwindcss`
4747

48-
The `tailwindcss-ruby` gem is declared as a floating dependency of this gem, so by default you will get the most recent stable version. However, you can select a specific version of tailwind by pinning that gem to the analogous version in your application's `Gemfile`. For example,
48+
The `tailwindcss-ruby` gem is declared as a floating dependency of this gem, so by default you will get the most recent stable version. However, you can select a specific version of Tailwind CSS by pinning that gem to the analogous version in your application's `Gemfile`. For example,
4949

5050
``` ruby
5151
gem "tailwindcss-rails"
@@ -63,72 +63,53 @@ You can also use a local (npm-based) installation if you prefer, please go to ht
6363

6464
v4.x of this gem has been updated to work with Tailwind v4, including providing some help with upgrading your application.
6565

66-
A full explanation of a Tailwind v4 upgrade is out of scope for this README, so we strongly urge you to read the [official Tailwind v4 upgrade guide](https://tailwindcss.com/docs/upgrade-guide) before embarking on an upgrade to an existing large app.
66+
A full explanation of a Tailwind CSS v4 upgrade is out of scope for this README, so we **strongly urge** you to read the [official Tailwind CSS v4 upgrade guide](https://tailwindcss.com/docs/upgrade-guide) before embarking on an upgrade to an existing large app.
6767

68-
This gem will help with some of the mechanics of the upgrade, however.
68+
This gem will help with some of the mechanics of the upgrade:
69+
70+
- update some generated files to handle breaking changes in v4 of this gem,
71+
- update some local project files to meet some Tailwind CSS v4 conventions,
72+
- attempt to run the [upstream v4 upgrade tool](https://tailwindcss.com/docs/upgrade-guide#using-the-upgrade-tool).
6973

7074

7175
### You don't _have_ to upgrade
7276

73-
Keep in mind that you don't _need_ to upgrade. You can stay on Tailwind v3 for the foreseeable future if you prefer not to migrate now, or if your migration runs into problems.
77+
Keep in mind that you don't _need_ to upgrade. You can stay on Tailwind CSS v3 for the foreseeable future if you prefer not to migrate now, or if your migration runs into problems.
7478

75-
Just make sure you're either pinned to v3.3.1 of this gem:
79+
If you don't want to upgrade, then pin your application to v3.3.1 of this gem:
7680

7781
``` ruby
7882
# Gemfile
79-
gem "tailwindcss-rails", "3.3.1" # which transitively pins tailwindcss-ruby to v3
83+
gem "tailwindcss-rails", "~> 3.3.1" # which transitively pins tailwindcss-ruby to v3
8084
```
8185

82-
or if you're on an earlier version of this gem, make sure you're pinning the version of **both** `tailwindcss-rails` and `tailwindcss-ruby`:
86+
If you're on an earlier version of this gem, `<= 3.3.0`, then make sure you're pinning the version of **both** `tailwindcss-rails` and `tailwindcss-ruby`:
8387

8488
``` ruby
8589
# Gemfile
8690
gem "tailwindcss-rails", "~> 3.3"
87-
gem "tailwindcss-ruby", "~> 3.4"
91+
gem "tailwindcss-ruby", "~> 3.4" # only necessary with tailwindcss-rails <= 3.3.0
8892
```
8993

9094

9195
### Upgrade steps
9296

93-
First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4.
97+
> [!WARNING]
98+
> In applications using Tailwind plugins without JavaScript tooling, these upgrade steps may fail to fully migrate `tailwind.config.js` because the upstream upgrade tool needs the Tailwind plugins to be installed and available through a JavaScript package manager. If you see errors from the upstream upgrade tool, you should try following the additional steps in [Updating CSS class names for v4](#updating-css-class-names-for-v4) which will help you install (temporarily!) the necessary packages and clean up afterwards.
9499
100+
First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4.
95101

96102
```html
97103
# Gemfile
98104
gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4
99105
```
100106

101-
If you want to migrate class names for v4 (optional), apply this [step](#upgrading-class-names-for-v4) and continue this guide.
102-
103-
Add the following line to the `.gitignore` file:
104-
105-
```gitignore
106-
/node_modules
107-
```
108-
(So the Tailwind update tool won’t dig through your node_modules files and infer incorrect migrations, because it complies with ``.gitignore`` constraints)
107+
If you want to migrate CSS class names for v4 (this is an optional step!), jump to [Updating CSS class names for v4](#updating-css-class-names-for-v4) before continuing.
109108

110-
Then create a ``package.json`` in the root of the project:
109+
Then, run `bin/rails tailwindcss:upgrade`. 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.
111110

112-
```jsonc
113-
{
114-
"name": "app_name",
115-
"version": "1.0.0",
116-
"dependencies": {
117-
"tailwindcss": "^3.4.17", // Mandatory!!
118-
// Install all plugins and modules that are referenced in tailwind.config.js
119-
"@tailwindcss/aspect-ratio": "^0.4.2",
120-
"@tailwindcss/container-queries": "^0.1.1",
121-
"@tailwindcss/forms": "^0.5.10",
122-
"@tailwindcss/typography": "^0.5.16"
123-
// And so on...
124-
}
125-
}
126-
```
127-
**Run** ``npm install`` (or ``yarn install`` if using ``yarn``)
128-
129-
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.
130-
131-
Here's what the upgrade task does:
111+
<details>
112+
<summary>Here's a detailed list of what the upgrade task does.</summary>
132113

133114
- Cleans up some things in the generated `config/tailwind.config.js`.
134115
- If present, moves `config/postcss.config.js` to the root directory.
@@ -137,6 +118,8 @@ Here's what the upgrade task does:
137118
- Removes references to the Inter font from the application layout.
138119
- Runs the upstream upgrader (note: requires `npx` to run the one-time upgrade, but highly recommended).
139120

121+
</details>
122+
140123
<details>
141124
<summary>Here's what that upgrade looks like on a vanilla Rails app.</summary>
142125

@@ -178,7 +161,7 @@ Done in 56ms
178161
</details>
179162
180163
181-
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)!
164+
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) and try following the additional steps in [Updating CSS class names for v4](#updating-css-class-names-for-v4).
182165
183166
184167
### Troubleshooting
@@ -187,14 +170,45 @@ You may want to check out [TailwindCSS v4 - upgrade experience report · rails/t
187170
188171
We know there are some cases we haven't addressed with the upgrade task:
189172
190-
- 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.
173+
- In applications using Tailwind plugins without JavaScript tooling, these upgrade steps may fail to fully migrate `tailwind.config.js` because the upstream upgrade tool needs the Tailwind plugins to be installed and available through a JavaScript package manager. If you see errors from the upstream upgrade tool, you should try following the additional steps in [Updating CSS class names for v4](#updating-css-class-names-for-v4) which will help you install (temporarily!) the necessary packages and clean up afterwards.
191174
192175
We'll try to improve the upgrade process over time, but for now you may need to do some manual work to upgrade.
193176
194177
195178
### Updating CSS class names for v4
196179
197-
Before running the upgrade task, go to ``config/tailwind.config.js`` update the ``content`` part to:
180+
> [!NOTE]
181+
> If you'd like to help automate these steps, please drop a note to the maintainers in [this discussion thread](https://github.com/rails/tailwindcss-rails/discussions/450).
182+
183+
With some additional manual work the upstream upgrade tool will update your application's CSS class names to v4 conventions. **This is an optional step that requires a JavaScript toolchain.**
184+
185+
**Add** the following line to the `.gitignore` file, to prevent the upstream upgrade tool from accessing node_modules files.
186+
187+
```gitignore
188+
/node_modules
189+
```
190+
191+
**Create** a `package.json` in the root of the project:
192+
193+
```jsonc
194+
{
195+
"name": "app_name",
196+
"version": "1.0.0",
197+
"dependencies": {
198+
"tailwindcss": "^3.4.17", // Mandatory!!
199+
// Install all plugins and modules that are referenced in tailwind.config.js
200+
"@tailwindcss/aspect-ratio": "^0.4.2",
201+
"@tailwindcss/container-queries": "^0.1.1",
202+
"@tailwindcss/forms": "^0.5.10",
203+
"@tailwindcss/typography": "^0.5.16"
204+
// And so on...
205+
}
206+
}
207+
```
208+
209+
**Run** `npm install` (or `yarn install` if using `yarn`)
210+
211+
**Update** `config/tailwind.config.js` and temporarily change the `content` part to have an additional `.` on all paths so they are relative to the config file:
198212
199213
```js
200214
content: [
@@ -204,17 +218,19 @@ Before running the upgrade task, go to ``config/tailwind.config.js`` update the
204218
'../app/views/**/*.{erb,haml,html,slim}'
205219
],
206220
```
207-
(Just add an additional ``.`` to all the paths referenced)
208221
209-
Run the upstream upgrader as instructed above.
222+
(Just add an additional `.` to all the paths referenced)
223+
224+
**Run** the upstream upgrader as instructed above.
210225
211-
Then, once you've run that successfully:
226+
Then, once you've run that successfully, clean up:
212227
213-
- **Delete** ``package.json``, ``node_modules/`` and ``package-lock.json`` (or ``yarn.lock``), plus remove ``/node_modules`` from ``.gitignore``.
228+
- **Delete** `package.json`, `node_modules/` and `package-lock.json` (or `yarn.lock`), plus remove `/node_modules` from `.gitignore`.
214229
- **Go** to your CSS file and remove the following line (if present):
215230
```css
216231
@plugin '@tailwindcss/container-queries';
217232
```
233+
- **Revert** the changes to `config/tailwind.config.js` so that paths are once again relative to the application root.
218234
219235
220236
## Developing with Tailwindcss
@@ -311,7 +327,7 @@ Running `bin/dev` invokes Foreman to start both the Tailwind watch process and t
311327
312328
### Using with PostCSS
313329
314-
If you want to use PostCSS as a preprocessor, create a custom `postcss.config.js` in your project root directory, and that file will be loaded by tailwind automatically.
330+
If you want to use PostCSS as a preprocessor, create a custom `postcss.config.js` in your project root directory, and that file will be loaded by Tailwind automatically.
315331
316332
For example, to enable nesting:
317333
@@ -324,7 +340,7 @@ export default {
324340
}
325341
```
326342
327-
⚠ Note that PostCSS is a javascript tool with its own prerequisites! By default `tailwindcss-rails` does not require any javascript tooling, so in order to use PostCSS, a `package.json` with dependencies for your plugins and a package manager like `yarn` or `npm` is required, for example:
343+
⚠ Note that PostCSS is a JavaScript tool with its own prerequisites! By default `tailwindcss-rails` does not require any JavaScript tooling, so in order to use PostCSS, a `package.json` with dependencies for your plugins and a package manager like `yarn` or `npm` is required, for example:
328344
329345
```json
330346
// package.json

tailwindcss-rails.gemspec

+14
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,18 @@ Gem::Specification.new do |spec|
2020

2121
spec.add_dependency "railties", ">= 7.0.0"
2222
spec.add_dependency "tailwindcss-ruby", "~> 4.0"
23+
24+
# TODO: remove this after a suitable period of time after the v4.0.0 release.
25+
spec.post_install_message = <<~TEXT
26+
== Upgrading to Tailwind CSS v4 ==
27+
28+
If you are upgrading to tailwindcss-rails 4.x, please read the upgrade guide at:
29+
30+
https://github.com/rails/tailwindcss-rails/blob/main/README.md#upgrading-your-application-from-tailwind-v3-to-v4
31+
32+
If you're not ready to upgrade yet, please pin to version 3 in your Gemfile:
33+
34+
gem "tailwindcss-rails", "~> 3.3.1"
35+
36+
TEXT
2337
end

0 commit comments

Comments
 (0)