Skip to content

Commit e29c64f

Browse files
authored
Merge pull request #467 from rails/flavorjones-document-v4-upgrade
doc: add upgrade notes to the README
2 parents d86e74b + 1edc8c0 commit e29c64f

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

Diff for: CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
## next / unreleased
22

3+
## v4.0.0.rc1 / unreleased
4+
5+
### Upgrade to Tailwind CSS v4
6+
7+
General changes:
8+
9+
- Dependency on `tailwindcss-ruby` set to `~> 4.0`.
10+
- The location of (optional) `postcss.config.js` has moved from the `config/` directory to the app root.
11+
12+
Changes to the `tailwindcss:install` task:
13+
14+
- The `tailwindcss:install` task no longer installs `config/tailwind.config.js`.
15+
- The Inter font is no longer packaged with the gem.
16+
- Some Tailwind class names are updated for v4.
17+
18+
New task `tailwindcss:upgrade` upgrades many apps cleanly:
19+
20+
- Cleans up some things in the generated `config/tailwind.config.js`.
21+
- Runs the upstream upgrader (note: requires `npx` to run the one-time upgrade, but highly recommended).
22+
- Removes references to the Inter font from the application layout.
23+
- If present, moves `config/postcss.config.js` to the root directory.
24+
25+
Thanks to @EricGusmao and @excid3 for their help and advice on this work.
26+
27+
328
## v3.3.0 / 2025-01-19
429

530
* Add support for using the puma plugin in a standalone puma process (outside of `rails server`). (#458) @flavorjones

Diff for: README.md

+107-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
- [Installation](#installation)
1010
* [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss)
1111
* [Using a local installation of `tailwindcss`](#using-a-local-installation-of-tailwindcss)
12+
- [Upgrading your application from Tailwind v3 to v4](#upgrading-your-application-from-tailwind-v3-to-v4)
13+
* [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade)
14+
* [Upgrade steps](#upgrade-steps)
15+
* [Troubleshooting](#troubleshooting)
1216
- [Developing with Tailwindcss](#developing-with-tailwindcss)
1317
* [Configuration and commands](#configuration-and-commands)
1418
* [Building for production](#building-for-production)
@@ -17,7 +21,7 @@
1721
* [Live rebuild](#live-rebuild)
1822
* [Using with PostCSS](#using-with-postcss)
1923
* [Custom inputs or outputs](#custom-inputs-or-outputs)
20-
- [Troubleshooting](#troubleshooting)
24+
- [Troubleshooting](#troubleshooting-1)
2125
* [Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin](#lost-keystrokes-or-hanging-when-using-terminal-based-debugging-tools-eg-irb-pry-rubydebugetc-with-the-puma-plugin)
2226
* [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely)
2327
* [Conflict with sassc-rails](#conflict-with-sassc-rails)
@@ -55,6 +59,106 @@ gem "tailwindcss-ruby", "3.4.13"
5559
You can also use a local (npm-based) installation if you prefer, please go to https://github.com/flavorjones/tailwindcss-ruby for more information.
5660

5761

62+
## Upgrading your application from Tailwind v3 to v4
63+
64+
v4.x of this gem has been updated to work with Tailwind v4, including providing some help with upgrading your application.
65+
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.
67+
68+
This gem will help with some of the mechanics of the upgrade, however.
69+
70+
### You don't _have_ to upgrade
71+
72+
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.
73+
74+
Just make sure you're pinning the version of **both** `tailwindcss-rails` and `tailwindcss-ruby`:
75+
76+
``` ruby
77+
# Gemfile
78+
gem "tailwindcss-rails", "~> 3.3"
79+
gem "tailwindcss-ruby", "~> 3.4"
80+
```
81+
82+
83+
### Upgrade steps
84+
85+
First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4.
86+
87+
``` html
88+
# Gemfile
89+
gem "tailwindcss-rails", "~> 4.0"
90+
```
91+
92+
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.
93+
94+
Here's what the upgrade task does:
95+
96+
- Cleans up some things in the generated `config/tailwind.config.js`.
97+
- Runs the upstream upgrader (note: requires `npx` to run the one-time upgrade, but highly recommended).
98+
- Removes references to the Inter font from the application layout.
99+
- If present, moves `config/postcss.config.js` to the root directory.
100+
101+
Here's what that upgrade looks like on a vanilla Rails app:
102+
103+
``` sh
104+
$ bin/rails tailwindcss:upgrade
105+
apply /path/to/tailwindcss-rails/lib/install/upgrade_tailwindcss.rb
106+
Removing references to 'defaultTheme' from /home/user/myapp/config/tailwind.config.js
107+
gsub config/tailwind.config.js
108+
Running the upstream Tailwind CSS upgrader
109+
run npx @tailwindcss/upgrade@next --force --config /home/user/myapp/config/tailwind.config.js from "."
110+
≈ tailwindcss v4.0.0
111+
112+
│ Searching for CSS files in the current directory and its subdirectories…
113+
114+
│ ↳ Linked `./config/tailwind.config.js` to `./app/assets/stylesheets/application.tailwind.css`
115+
116+
│ Migrating JavaScript configuration files…
117+
118+
│ ↳ The configuration file at `./config/tailwind.config.js` could not be automatically migrated to the new CSS
119+
│ configuration format, so your CSS has been updated to load your existing configuration file.
120+
121+
│ Migrating templates…
122+
123+
│ ↳ Migrated templates for configuration file: `./config/tailwind.config.js`
124+
125+
│ Migrating stylesheets…
126+
127+
│ ↳ Migrated stylesheet: `./app/assets/stylesheets/application.tailwind.css`
128+
129+
│ ↳ No PostCSS config found, skipping migration.
130+
131+
│ Updating dependencies…
132+
133+
│ Could not detect a package manager. Please manually update `tailwindcss` to v4.
134+
135+
│ Verify the changes and commit them to your repository.
136+
137+
Strip Inter font CSS from application layout
138+
gsub app/views/layouts/application.html.erb
139+
Compile initial Tailwind build
140+
run rails tailwindcss:build from "."
141+
≈ tailwindcss v4.0.0
142+
143+
Done in 52ms
144+
run bundle install --quiet
145+
```
146+
147+
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)!
148+
149+
150+
### Troubleshooting
151+
152+
You may want to check out [TailwindCSS v4 - upgrade experience report · rails/tailwindcss-rails · Discussion #450](https://github.com/rails/tailwindcss-rails/discussions/450) if you're having trouble upgrading.
153+
154+
We know there are some cases we haven't addressed with the upgrade task:
155+
156+
- If the user isn’t using PostCSS, some migrations (e.g., updating class names in the view files) may fail
157+
- 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.
158+
159+
We'll try to improve the upgrade process over time, but for now you may need to do some manual work to upgrade.
160+
161+
58162
## Developing with Tailwindcss
59163
60164
### Configuration and commands
@@ -147,12 +251,12 @@ Running `bin/dev` invokes Foreman to start both the Tailwind watch process and t
147251
148252
### Using with PostCSS
149253
150-
If you want to use PostCSS as a preprocessor, create a custom `config/postcss.config.js` and that file will be loaded by tailwind automatically.
254+
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.
151255
152256
For example, to enable nesting:
153257
154258
```js
155-
// config/postcss.config.js
259+
// postcss.config.js
156260
module.exports = {
157261
plugins: {
158262
'postcss-import': {},

0 commit comments

Comments
 (0)