|
9 | 9 | - [Installation](#installation)
|
10 | 10 | * [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss)
|
11 | 11 | * [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) |
12 | 16 | - [Developing with Tailwindcss](#developing-with-tailwindcss)
|
13 | 17 | * [Configuration and commands](#configuration-and-commands)
|
14 | 18 | * [Building for production](#building-for-production)
|
|
17 | 21 | * [Live rebuild](#live-rebuild)
|
18 | 22 | * [Using with PostCSS](#using-with-postcss)
|
19 | 23 | * [Custom inputs or outputs](#custom-inputs-or-outputs)
|
20 |
| -- [Troubleshooting](#troubleshooting) |
| 24 | +- [Troubleshooting](#troubleshooting-1) |
21 | 25 | * [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)
|
22 | 26 | * [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely)
|
23 | 27 | * [Conflict with sassc-rails](#conflict-with-sassc-rails)
|
@@ -55,6 +59,106 @@ gem "tailwindcss-ruby", "3.4.13"
|
55 | 59 | You can also use a local (npm-based) installation if you prefer, please go to https://github.com/flavorjones/tailwindcss-ruby for more information.
|
56 | 60 |
|
57 | 61 |
|
| 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 | +
|
58 | 162 | ## Developing with Tailwindcss
|
59 | 163 |
|
60 | 164 | ### Configuration and commands
|
@@ -147,12 +251,12 @@ Running `bin/dev` invokes Foreman to start both the Tailwind watch process and t
|
147 | 251 |
|
148 | 252 | ### Using with PostCSS
|
149 | 253 |
|
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. |
151 | 255 |
|
152 | 256 | For example, to enable nesting:
|
153 | 257 |
|
154 | 258 | ```js
|
155 |
| -// config/postcss.config.js |
| 259 | +// postcss.config.js |
156 | 260 | module.exports = {
|
157 | 261 | plugins: {
|
158 | 262 | 'postcss-import': {},
|
|
0 commit comments