tailwindcss-rails 3.3.2 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +279 -56
- data/lib/generators/tailwindcss/authentication/authentication_generator.rb +2 -0
- data/lib/generators/tailwindcss/authentication/templates/app/views/passwords/edit.html.erb +3 -3
- data/lib/generators/tailwindcss/authentication/templates/app/views/passwords/new.html.erb +2 -2
- data/lib/generators/tailwindcss/authentication/templates/app/views/sessions/new.html.erb +3 -3
- data/lib/generators/tailwindcss/scaffold/scaffold_generator.rb +1 -0
- data/lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt +8 -8
- data/lib/generators/tailwindcss/scaffold/templates/edit.html.erb.tt +2 -2
- data/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +9 -5
- data/lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt +1 -1
- data/lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt +7 -5
- data/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt +3 -5
- data/lib/generators/test_unit/scaffold/scaffold_generator.rb +21 -0
- data/lib/install/application.css +1 -0
- data/lib/install/{tailwindcss.rb → install_tailwindcss.rb} +12 -13
- data/lib/install/upgrade_tailwindcss.rb +69 -0
- data/lib/puma/plugin/tailwindcss.rb +1 -1
- data/lib/tailwindcss/commands.rb +9 -5
- data/lib/tailwindcss/engine.rb +6 -4
- data/lib/tailwindcss/engines.rb +23 -0
- data/lib/tailwindcss/version.rb +1 -1
- data/lib/tailwindcss-rails.rb +1 -0
- data/lib/tasks/build.rake +19 -6
- data/lib/tasks/install.rake +1 -1
- data/lib/tasks/upgrade.rake +6 -0
- metadata +22 -24
- data/app/assets/fonts/Inter-italic.alternates.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.cyrillic.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.extra.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.greek.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.latin-ext.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.latin.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.symbols.var.woff2 +0 -0
- data/app/assets/fonts/Inter-italic.vietnamese.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.alternates.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.cyrillic.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.extra.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.greek.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.latin-ext.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.latin.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.symbols.var.woff2 +0 -0
- data/app/assets/fonts/Inter-roman.vietnamese.var.woff2 +0 -0
- data/app/assets/stylesheets/inter-font.css +0 -194
- data/lib/install/application.tailwind.css +0 -13
- data/lib/install/tailwind.config.js +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2520a011b4bef6255ee93a06b90ca76482ac3cf38236f6031226336033794220
|
4
|
+
data.tar.gz: 89df63d397c8ebaf774129cc9cda90291d1cff0f7bcc29ff55230925c697f7aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff813245fc1a40d53f4a14e264dbd50a7c6312be4507e60d334d8da8da38e3f67bdf258a642db045e56847bd71cb114680b81bf3925995ae03157db51e36f53
|
7
|
+
data.tar.gz: 750be07cbd111aae1c7f2746f58c3b3ec9db86812eb06099130e279bd10f92897e201caed26c44597280d9c64942465f7822f56897fbe2bcc3235b2a82a04369
|
data/README.md
CHANGED
@@ -9,41 +9,47 @@
|
|
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 a v4 upgrade](#troubleshooting-a-v4-upgrade)
|
16
|
+
* [Updating CSS class names for v4](#updating-css-class-names-for-v4)
|
12
17
|
- [Developing with Tailwindcss](#developing-with-tailwindcss)
|
13
18
|
* [Configuration and commands](#configuration-and-commands)
|
14
19
|
* [Building for production](#building-for-production)
|
15
20
|
* [Building for testing](#building-for-testing)
|
16
21
|
* [Building unminified assets](#building-unminified-assets)
|
17
22
|
* [Live rebuild](#live-rebuild)
|
23
|
+
* [Using Tailwind plugins](#using-tailwind-plugins)
|
18
24
|
* [Using with PostCSS](#using-with-postcss)
|
19
25
|
* [Custom inputs or outputs](#custom-inputs-or-outputs)
|
26
|
+
* [Rails Engines support (Experimental)](#rails-engines-support-experimental)
|
20
27
|
- [Troubleshooting](#troubleshooting)
|
28
|
+
* [The `watch` command is hanging](#the-watch-command-is-hanging)
|
21
29
|
* [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
30
|
* [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely)
|
23
31
|
* [Conflict with sassc-rails](#conflict-with-sassc-rails)
|
24
32
|
* [Class names must be spelled out](#class-names-must-be-spelled-out)
|
25
33
|
* [`ERROR: Cannot find the tailwindcss executable` for supported platform](#error-cannot-find-the-tailwindcss-executable-for-supported-platform)
|
26
34
|
* [Using asset-pipeline assets](#using-asset-pipeline-assets)
|
27
|
-
* [Conflict with pre-existing asset pipeline stylesheets](#conflict-with-pre-existing-asset-pipeline-stylesheets)
|
28
35
|
- [License](#license)
|
29
36
|
|
30
37
|
<!-- tocstop -->
|
31
38
|
|
32
39
|
## Installation
|
33
40
|
|
34
|
-
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:
|
41
|
+
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:
|
35
42
|
|
36
43
|
1. Run `./bin/bundle add tailwindcss-rails`
|
37
44
|
2. Run `./bin/rails tailwindcss:install`
|
38
45
|
|
39
|
-
This gem depends on the `tailwindcss-ruby` gem to install a working
|
40
|
-
|
46
|
+
This gem depends on the `tailwindcss-ruby` gem to install a working Tailwind CLI executable.
|
41
47
|
|
42
48
|
### Choosing a specific version of `tailwindcss`
|
43
49
|
|
44
|
-
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
|
50
|
+
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,
|
45
51
|
|
46
|
-
```
|
52
|
+
```ruby
|
47
53
|
gem "tailwindcss-rails"
|
48
54
|
|
49
55
|
# pin to tailwindcss version 3.4.13
|
@@ -54,22 +60,197 @@ gem "tailwindcss-ruby", "3.4.13"
|
|
54
60
|
|
55
61
|
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
62
|
|
63
|
+
## Upgrading your application from Tailwind v3 to v4
|
64
|
+
|
65
|
+
v4.x of this gem has been updated to work with Tailwind v4, including providing some help with upgrading your application.
|
66
|
+
|
67
|
+
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.
|
68
|
+
|
69
|
+
This gem will help with some of the mechanics of the upgrade:
|
70
|
+
|
71
|
+
- update some generated files to handle breaking changes in v4 of this gem,
|
72
|
+
- update some local project files to meet some Tailwind CSS v4 conventions,
|
73
|
+
- attempt to run the [upstream v4 upgrade tool](https://tailwindcss.com/docs/upgrade-guide#using-the-upgrade-tool).
|
74
|
+
|
75
|
+
### You don't _have_ to upgrade
|
76
|
+
|
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.
|
78
|
+
|
79
|
+
If you don't want to upgrade, then pin your application to v3.3.1 of this gem:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Gemfile
|
83
|
+
gem "tailwindcss-rails", "~> 3.3.1" # which transitively pins tailwindcss-ruby to v3
|
84
|
+
```
|
85
|
+
|
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`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# Gemfile
|
90
|
+
gem "tailwindcss-rails", "~> 3.3"
|
91
|
+
gem "tailwindcss-ruby", "~> 3.4" # only necessary with tailwindcss-rails <= 3.3.0
|
92
|
+
```
|
93
|
+
|
94
|
+
### Upgrade steps
|
95
|
+
|
96
|
+
> [!WARNING]
|
97
|
+
> 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.
|
98
|
+
|
99
|
+
First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
# Gemfile
|
103
|
+
gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4
|
104
|
+
```
|
105
|
+
|
106
|
+
**Update** path references to any existing css files imported in `app/assets/stylesheets/application.tailwind.css` so that they will resolve when the file is moved to `app/assets/tailwind/application.css`.
|
107
|
+
|
108
|
+
```diff
|
109
|
+
-@import "pagy.css";
|
110
|
+
+@import "../stylesheets/pagy.css";
|
111
|
+
```
|
112
|
+
|
113
|
+
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.
|
114
|
+
|
115
|
+
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.
|
116
|
+
|
117
|
+
<details>
|
118
|
+
<summary>Here's a detailed list of what the upgrade task does.</summary>
|
119
|
+
|
120
|
+
- Cleans up some things in the generated `config/tailwind.config.js`.
|
121
|
+
- If present, moves `config/postcss.config.js` to the root directory.
|
122
|
+
- If present, moves `app/assets/stylesheets/application.tailwind.css` to `app/assets/tailwind/application.css`.
|
123
|
+
- Removes unnecessary `stylesheet_link_tag "tailwindcss"` tags from the application layout.
|
124
|
+
- Removes references to the Inter font from the application layout.
|
125
|
+
- Runs v4.1.4 of the upstream upgrader (note: requires `npx` to run the one-time upgrade, but highly recommended).
|
126
|
+
|
127
|
+
</details>
|
128
|
+
|
129
|
+
<details>
|
130
|
+
<summary>Here's what that upgrade looks like on a vanilla Rails app.</summary>
|
131
|
+
|
132
|
+
```sh
|
133
|
+
$ bin/rails tailwindcss:upgrade
|
134
|
+
apply /path/to/tailwindcss-rails/lib/install/upgrade_tailwindcss.rb
|
135
|
+
Removing references to 'defaultTheme' from /home/user/myapp/config/tailwind.config.js
|
136
|
+
gsub config/tailwind.config.js
|
137
|
+
Strip Inter font CSS from application layout
|
138
|
+
gsub app/views/layouts/application.html.erb
|
139
|
+
Remove unnecessary stylesheet_link_tag from application layout
|
140
|
+
gsub app/views/layouts/application.html.erb
|
141
|
+
Moving /home/user/myapp/app/assets/stylesheets/application.tailwind.css to /home/user/myapp/app/assets/tailwind/application.css
|
142
|
+
create app/assets/tailwind/application.css
|
143
|
+
remove app/assets/stylesheets/application.tailwind.css
|
144
|
+
10.9.0
|
145
|
+
Running the upstream Tailwind CSS upgrader
|
146
|
+
run npx @tailwindcss/upgrade@4.1.4 --force --config /home/user/myapp/config/tailwind.config.js from "."
|
147
|
+
≈ tailwindcss v4.0.0
|
148
|
+
│ Searching for CSS files in the current directory and its subdirectories…
|
149
|
+
│ ↳ Linked `./config/tailwind.config.js` to `./app/assets/tailwind/application.css`
|
150
|
+
│ Migrating JavaScript configuration files…
|
151
|
+
│ ↳ The configuration file at `./config/tailwind.config.js` could not be automatically migrated to the new CSS
|
152
|
+
│ configuration format, so your CSS has been updated to load your existing configuration file.
|
153
|
+
│ Migrating templates…
|
154
|
+
│ ↳ Migrated templates for configuration file: `./config/tailwind.config.js`
|
155
|
+
│ Migrating stylesheets…
|
156
|
+
│ ↳ Migrated stylesheet: `./app/assets/tailwind/application.css`
|
157
|
+
│ ↳ No PostCSS config found, skipping migration.
|
158
|
+
│ Updating dependencies…
|
159
|
+
│ Could not detect a package manager. Please manually update `tailwindcss` to v4.
|
160
|
+
│ Verify the changes and commit them to your repository.
|
161
|
+
Compile initial Tailwind build
|
162
|
+
run rails tailwindcss:build from "."
|
163
|
+
≈ tailwindcss v4.0.0
|
164
|
+
Done in 56ms
|
165
|
+
run bundle install --quiet
|
166
|
+
```
|
167
|
+
|
168
|
+
</details>
|
169
|
+
|
170
|
+
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).
|
171
|
+
|
172
|
+
### Troubleshooting a v4 upgrade
|
173
|
+
|
174
|
+
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.
|
175
|
+
|
176
|
+
We know there are some cases we haven't addressed with the upgrade task:
|
177
|
+
|
178
|
+
- 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.
|
179
|
+
|
180
|
+
We'll try to improve the upgrade process over time, but for now you may need to do some manual work to upgrade.
|
181
|
+
|
182
|
+
### Updating CSS class names for v4
|
183
|
+
|
184
|
+
> [!NOTE]
|
185
|
+
> 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).
|
186
|
+
|
187
|
+
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.**
|
188
|
+
|
189
|
+
**Add** the following line to the `.gitignore` file, to prevent the upstream upgrade tool from accessing node_modules files.
|
190
|
+
|
191
|
+
```gitignore
|
192
|
+
/node_modules
|
193
|
+
```
|
194
|
+
|
195
|
+
**Create** or **update** a `package.json` in the root of the project:
|
196
|
+
|
197
|
+
```jsonc
|
198
|
+
{
|
199
|
+
"name": "app_name",
|
200
|
+
"version": "1.0.0",
|
201
|
+
"dependencies": {
|
202
|
+
"tailwindcss": "^3.4.17", // Mandatory!!
|
203
|
+
// Install all plugins and modules that are referenced in tailwind.config.js
|
204
|
+
"@tailwindcss/aspect-ratio": "^0.4.2",
|
205
|
+
"@tailwindcss/container-queries": "^0.1.1",
|
206
|
+
"@tailwindcss/forms": "^0.5.10",
|
207
|
+
"@tailwindcss/typography": "^0.5.16",
|
208
|
+
// And so on...
|
209
|
+
},
|
210
|
+
}
|
211
|
+
```
|
212
|
+
|
213
|
+
**Run** `npm install` (or `yarn install` if using `yarn`)
|
214
|
+
|
215
|
+
**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:
|
216
|
+
|
217
|
+
```js
|
218
|
+
content: [
|
219
|
+
'../public/*.html',
|
220
|
+
'../app/helpers/**/*.rb',
|
221
|
+
'../app/javascript/**/*.js',
|
222
|
+
'../app/views/**/*.{erb,haml,html,slim}'
|
223
|
+
],
|
224
|
+
```
|
225
|
+
|
226
|
+
(Just add an additional `.` to all the paths referenced)
|
227
|
+
|
228
|
+
**Run** the upstream upgrader as instructed above.
|
229
|
+
|
230
|
+
Then, once you've run that successfully, clean up:
|
231
|
+
|
232
|
+
- **Review** `package.json` to remove unnecessary modules.
|
233
|
+
- This includes modules added for the period of upgrade.
|
234
|
+
- If you don't need any modules besides `tailwindcss` itself, **delete** `package.json`, `node_modules/` and `package-lock.json` (or `yarn.lock`), plus remove `/node_modules` from `.gitignore`.
|
235
|
+
- **Go** to your CSS file and remove the following line (if present):
|
236
|
+
```css
|
237
|
+
@plugin '@tailwindcss/container-queries';
|
238
|
+
```
|
239
|
+
- **Revert** the changes to `config/tailwind.config.js` so that paths are once again relative to the application root.
|
57
240
|
|
58
241
|
## Developing with Tailwindcss
|
59
242
|
|
60
243
|
### Configuration and commands
|
61
244
|
|
62
|
-
####
|
245
|
+
#### Input file: `app/assets/tailwind/application.css`
|
63
246
|
|
64
|
-
|
247
|
+
The `tailwindcss:install` task will generate a Tailwind input file in `app/assets/tailwind/application.css`. This is where you import the plugins you want to use and where you can setup your custom `@apply` rules.
|
65
248
|
|
66
|
-
|
67
|
-
|
68
|
-
The installer will generate a Tailwind input file in `app/assets/stylesheets/application.tailwind.css`. This is where you import the plugins you want to use, and where you can setup your custom `@apply` rules.
|
249
|
+
⚠ The location of this file changed in v4, from `app/assets/stylesheets/application.tailwind.css` to `app/assets/tailwind/application.css`. The `tailwindcss:upgrade` task will move it for you.
|
69
250
|
|
70
251
|
#### Output file: `app/assets/builds/tailwind.css`
|
71
252
|
|
72
|
-
When you run `rails tailwindcss:build`, the input file will be used to generate the output in `app/assets/builds/tailwind.css`. That's the output CSS that you'll include in your app
|
253
|
+
When you run `rails tailwindcss:build`, the input file will be used to generate the output in `app/assets/builds/tailwind.css`. That's the output CSS that you'll include in your app.
|
73
254
|
|
74
255
|
#### Commands
|
75
256
|
|
@@ -91,21 +272,22 @@ This gem also makes available a Puma plugin to manage a live rebuild process whe
|
|
91
272
|
|
92
273
|
This gem also generates a `Procfile.dev` file which will run both the rails server and a live rebuild process (see "Live Rebuild" section below).
|
93
274
|
|
94
|
-
|
95
275
|
### Building for production
|
96
276
|
|
97
277
|
The `tailwindcss:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Tailwind output will be generated.
|
98
278
|
|
99
|
-
|
100
279
|
### Building for testing
|
101
280
|
|
102
281
|
The `tailwindcss:build` task is automatically attached to the `test:prepare` Rake task. This task runs before test commands. If you run `bin/rails test` in your CI environment, your Tailwind output will be generated before tests run.
|
103
282
|
|
104
|
-
|
105
283
|
### Building unminified assets
|
106
284
|
|
107
|
-
If you want unminified assets, you can
|
285
|
+
If you want unminified assets, you can:
|
286
|
+
|
287
|
+
- pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
|
288
|
+
- set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value
|
108
289
|
|
290
|
+
If both values are set, the environment variable will take precedence over the rake task argument.
|
109
291
|
|
110
292
|
### Live rebuild
|
111
293
|
|
@@ -115,7 +297,6 @@ While you're developing your application, you want to run Tailwind in "watch" mo
|
|
115
297
|
- or run `rails tailwindcss:watch` as a separate process,
|
116
298
|
- or run `bin/dev` which uses [Foreman](https://github.com/ddollar/foreman)
|
117
299
|
|
118
|
-
|
119
300
|
#### Puma plugin
|
120
301
|
|
121
302
|
This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` configuration:
|
@@ -126,7 +307,6 @@ plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
|
|
126
307
|
|
127
308
|
and then running `rails server` (or just `puma`) will run the Tailwind watch process in the background.
|
128
309
|
|
129
|
-
|
130
310
|
#### Run `rails tailwindcss:watch`
|
131
311
|
|
132
312
|
This is a flexible command, which can be run with a few different options.
|
@@ -143,31 +323,51 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container,
|
|
143
323
|
|
144
324
|
If you are running `rails tailwindcss:watch` in a docker container without a tty, pass the `always` argument to the task to instruct tailwindcss to keep the watcher alive even when `stdin` is closed: `rails tailwindcss:watch[always]`. If you use `bin/dev` then you should modify your `Procfile.dev`.
|
145
325
|
|
146
|
-
|
147
326
|
#### Foreman
|
148
327
|
|
149
328
|
Running `bin/dev` invokes Foreman to start both the Tailwind watch process and the rails server in development mode based on your `Procfile.dev` file.
|
150
329
|
|
330
|
+
### Using Tailwind plugins
|
331
|
+
|
332
|
+
If you want to use Tailwind plugins, they can be installed using `package.json`.
|
333
|
+
|
334
|
+
Using Yarn:
|
335
|
+
|
336
|
+
```sh
|
337
|
+
[ ! -f package.json ] && yarn init
|
338
|
+
yarn add daisyui # example
|
339
|
+
```
|
340
|
+
|
341
|
+
Using npm:
|
342
|
+
|
343
|
+
```sh
|
344
|
+
npm init
|
345
|
+
npm add daisyui # example
|
346
|
+
```
|
347
|
+
|
348
|
+
Than use `@plugin` annotation in `app/assets/tailwind/application.css`:
|
349
|
+
|
350
|
+
```css
|
351
|
+
@import "tailwindcss";
|
352
|
+
@plugin "daisyui";
|
353
|
+
```
|
151
354
|
|
152
355
|
### Using with PostCSS
|
153
356
|
|
154
|
-
If you want to use PostCSS as a preprocessor, create a custom `
|
357
|
+
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.
|
155
358
|
|
156
359
|
For example, to enable nesting:
|
157
360
|
|
158
361
|
```js
|
159
|
-
//
|
160
|
-
|
362
|
+
// postcss.config.js
|
363
|
+
export default {
|
161
364
|
plugins: {
|
162
|
-
|
163
|
-
'tailwindcss/nesting': {},
|
164
|
-
tailwindcss: {},
|
165
|
-
autoprefixer: {},
|
365
|
+
"@tailwindcss/postcss": {},
|
166
366
|
},
|
167
|
-
}
|
367
|
+
};
|
168
368
|
```
|
169
369
|
|
170
|
-
⚠ Note that PostCSS is a
|
370
|
+
⚠ 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:
|
171
371
|
|
172
372
|
```json
|
173
373
|
// package.json
|
@@ -175,25 +375,58 @@ module.exports = {
|
|
175
375
|
"name": "my app",
|
176
376
|
"private": true,
|
177
377
|
"dependencies": {
|
178
|
-
"postcss
|
179
|
-
"
|
180
|
-
"postcss
|
181
|
-
"tailwindcss": "^3.4.1"
|
378
|
+
"@tailwindcss/postcss": "^4.0.0",
|
379
|
+
"tailwindcss": "^4.0.0",
|
380
|
+
"postcss": "^8.5.1"
|
182
381
|
}
|
183
382
|
}
|
184
383
|
```
|
185
384
|
|
186
385
|
Then you can use yarn or npm to install the dependencies.
|
187
386
|
|
188
|
-
|
189
387
|
### Custom inputs or outputs
|
190
388
|
|
191
389
|
If you need to use a custom input or output file, you can run `bundle exec tailwindcss` to access the platform-specific executable, and give it your own build options.
|
192
390
|
|
391
|
+
### Rails Engines support (Experimental)
|
392
|
+
|
393
|
+
_This feature is experimental and may change in the future. If you have feedback, please join the [discussion](https://github.com/rails/tailwindcss-rails/discussions/355)._
|
394
|
+
|
395
|
+
If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind/<engine_name>/engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/<engine_name>.css` on the first build/watch invocation or manual call for `rails tailwindcss:engines` so they can be included in your host application's Tailwind CSS by adding `@import "../builds/tailwind/<engine_name>"` to your `app/assets/tailwind/application.css` file.
|
396
|
+
|
397
|
+
> [!IMPORTANT]
|
398
|
+
> You must `@import` the engine CSS files in your `app/assets/tailwind/application.css` for the engine to be included in the build. By default, no engine CSS files are imported, and you must opt-in to using the file in your build.
|
193
399
|
|
194
400
|
## Troubleshooting
|
195
401
|
|
196
|
-
|
402
|
+
When having trouble with `tailwindcss:build` or `tailwindcss:watch`, the first thing you should do is collect some diagnostic information by setting the "verbose" flag, which will emit:
|
403
|
+
|
404
|
+
1. the command being run (so you can try running `tailwindcss` yourself without the gem's help)
|
405
|
+
2. additional debugging output from `tailwindcss` by setting the env var `DEBUG=1`
|
406
|
+
|
407
|
+
Here's what that looks like:
|
408
|
+
|
409
|
+
```sh
|
410
|
+
$ bin/rails tailwindcss:build[verbose]
|
411
|
+
|
412
|
+
Running: /path/to/tailwindcss-ruby-4.0.17-x86_64-linux-gnu/exe/x86_64-linux-gnu/tailwindcss -i /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/tailwind/application.css -o /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/builds/tailwind.css --minify
|
413
|
+
≈ tailwindcss v4.0.17
|
414
|
+
|
415
|
+
Done in 37ms
|
416
|
+
|
417
|
+
[38.22ms] [@tailwindcss/cli] (initial build)
|
418
|
+
[11.90ms] ↳ Setup compiler
|
419
|
+
[ 6.52ms] ↳ Scan for candidates
|
420
|
+
[10.39ms] ↳ Build CSS
|
421
|
+
[ 1.69ms] ↳ Optimize CSS
|
422
|
+
[ 5.80ms] ↳ Write output
|
423
|
+
```
|
424
|
+
|
425
|
+
### The `watch` command is hanging
|
426
|
+
|
427
|
+
There is a [known issue](https://github.com/tailwindlabs/tailwindcss/issues/17246#issuecomment-2753067488) running `tailwindcss -w` (that's the CLI in watch mode) when the utility `watchman` is also installed.
|
428
|
+
|
429
|
+
Please try uninstalling `watchman` and try running the watch task again.
|
197
430
|
|
198
431
|
### Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin
|
199
432
|
|
@@ -219,40 +452,30 @@ See https://github.com/flavorjones/tailwindcss-ruby for help.
|
|
219
452
|
|
220
453
|
### Using asset-pipeline assets
|
221
454
|
|
222
|
-
In Rails, you want to use [assets from the asset pipeline to get fingerprinting](https://guides.rubyonrails.org/asset_pipeline.html#
|
455
|
+
In Rails, you want to use [assets from the asset pipeline to get fingerprinting](https://guides.rubyonrails.org/asset_pipeline.html#fingerprinting-versioning-with-digest-based-urls). However, Tailwind isn't aware of those assets.
|
223
456
|
|
224
457
|
To use assets from the pipeline, use `url(image.svg)`. [Since Sprockets v3.3.0](https://github.com/rails/sprockets-rails/pull/476) `url(image.svg)` is rewritten to `/path/to/assets/image-7801e7538c6f1cc57aa75a5876ab0cac.svg` so output CSS will have the correct path to those assets.
|
225
458
|
|
226
459
|
```js
|
227
460
|
module.exports = {
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
}
|
461
|
+
theme: {
|
462
|
+
extend: {
|
463
|
+
backgroundImage: {
|
464
|
+
image: "url('image.svg')",
|
465
|
+
},
|
466
|
+
},
|
467
|
+
},
|
468
|
+
};
|
236
469
|
```
|
237
470
|
|
238
471
|
The inline version also works:
|
239
472
|
|
240
473
|
```html
|
241
|
-
<section class="bg-[url('image.svg')]">
|
474
|
+
<section class="bg-[url('image.svg')]">
|
475
|
+
Has the image as it's background
|
476
|
+
</section>
|
242
477
|
```
|
243
478
|
|
244
|
-
### Conflict with pre-existing asset pipeline stylesheets
|
245
|
-
|
246
|
-
If you get a warning `Unrecognized at-rule or error parsing at-rule ‘@tailwind’.` in the browser console after installation, you are incorrectly double-processing `application.tailwind.css`. This is a misconfiguration, even though the styles will be fully effective in many cases.
|
247
|
-
|
248
|
-
The file `application.tailwind.css` is installed when running `rails tailwindcss:install` and is placed alongside the common `application.css` in `app/assets/stylesheets`. Because the `application.css` in a newly generated Rails app includes a `require_tree .` directive, the asset pipeline incorrectly processes `application.tailwind.css`, where it should be taken care of by `tailwindcss`. The asset pipeline ignores TailwindCSS's at-directives, and the browser can't process them.
|
249
|
-
|
250
|
-
To fix the warning, you can either remove the `application.css`, if you don't plan to use the asset pipeline for stylesheets, and instead rely on TailwindCSS completely for styles. This is what this installer assumes.
|
251
|
-
|
252
|
-
Or, if you do want to keep using the asset pipeline in parallel, make sure to remove the `require_tree .` line from the `application.css`.
|
253
|
-
|
254
|
-
|
255
479
|
## License
|
256
480
|
|
257
481
|
Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
|
258
|
-
The Inter font is released under the [SIL Open Font License, Version 1.1](https://github.com/rsms/inter/blob/master/LICENSE.txt).
|
@@ -7,15 +7,15 @@
|
|
7
7
|
|
8
8
|
<%%= form_with url: password_path(params[:token]), method: :put, class: "contents" do |form| %>
|
9
9
|
<div class="my-5">
|
10
|
-
<%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-
|
10
|
+
<%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block shadow-sm rounded-md border border-gray-400 focus:outline-solid focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
11
11
|
</div>
|
12
12
|
|
13
13
|
<div class="my-5">
|
14
|
-
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-
|
14
|
+
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "block shadow-sm rounded-md border border-gray-400 focus:outline-solid focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
15
15
|
</div>
|
16
16
|
|
17
17
|
<div class="inline">
|
18
|
-
<%%= form.submit "Save", class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
18
|
+
<%%= form.submit "Save", class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
19
19
|
</div>
|
20
20
|
<%% end %>
|
21
21
|
</div>
|
@@ -7,11 +7,11 @@
|
|
7
7
|
|
8
8
|
<%%= form_with url: passwords_path, class: "contents" do |form| %>
|
9
9
|
<div class="my-5">
|
10
|
-
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 outline-
|
10
|
+
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow-sm rounded-md border border-gray-400 focus:outline-solid focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
11
11
|
</div>
|
12
12
|
|
13
13
|
<div class="inline">
|
14
|
-
<%%= form.submit "Email reset instructions", class: "rounded-lg px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
14
|
+
<%%= form.submit "Email reset instructions", class: "w-full sm:w-auto text-center rounded-lg px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
15
15
|
</div>
|
16
16
|
<%% end %>
|
17
17
|
</div>
|
@@ -11,16 +11,16 @@
|
|
11
11
|
|
12
12
|
<%%= form_with url: session_url, class: "contents" do |form| %>
|
13
13
|
<div class="my-5">
|
14
|
-
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
14
|
+
<%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow-sm rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
15
15
|
</div>
|
16
16
|
|
17
17
|
<div class="my-5">
|
18
|
-
<%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
18
|
+
<%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "block shadow-sm rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<div class="col-span-6 sm:flex sm:items-center sm:gap-4">
|
22
22
|
<div class="inline">
|
23
|
-
<%%= form.submit "Sign in", class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
23
|
+
<%%= form.submit "Sign in", class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
24
24
|
</div>
|
25
25
|
|
26
26
|
<div class="mt-4 text-sm text-gray-500 sm:mt-0">
|
@@ -12,32 +12,32 @@
|
|
12
12
|
<%% end %>
|
13
13
|
|
14
14
|
<% attributes.each do |attribute| -%>
|
15
|
-
<div class="my-5">
|
15
|
+
<div class="my-5<%= " flex items-center gap-2" if attribute.field_type == :checkbox || attribute.field_type == :check_box %>">
|
16
16
|
<% if attribute.password_digest? -%>
|
17
17
|
<%%= form.label :password %>
|
18
|
-
<%%= form.password_field :password, class: ["block shadow rounded-md border
|
18
|
+
<%%= form.password_field :password, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password].any?}] %>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<div class="my-5">
|
22
22
|
<%%= form.label :password_confirmation %>
|
23
|
-
<%%= form.password_field :password_confirmation, class: ["block shadow rounded-md border
|
23
|
+
<%%= form.password_field :password_confirmation, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:password_confirmation].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:password_confirmation].any?}] %>
|
24
24
|
<% elsif attribute.attachments? -%>
|
25
25
|
<%%= form.label :<%= attribute.column_name %> %>
|
26
|
-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: ["block shadow rounded-md border
|
26
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
|
27
27
|
<% else -%>
|
28
28
|
<%%= form.label :<%= attribute.column_name %> %>
|
29
29
|
<% if attribute.field_type == :textarea || attribute.field_type == :text_area -%>
|
30
|
-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: ["block shadow rounded-md border
|
30
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
|
31
31
|
<% elsif attribute.field_type == :checkbox || attribute.field_type == :check_box -%>
|
32
|
-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border
|
32
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow-sm rounded-md border order-first h-5 w-5", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
|
33
33
|
<% else -%>
|
34
|
-
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow rounded-md border
|
34
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].none?, "border-red-400 focus:outline-red-600": <%= model_resource_name %>.errors[:<%= attribute.column_name %>].any?}] %>
|
35
35
|
<% end -%>
|
36
36
|
<% end -%>
|
37
37
|
</div>
|
38
38
|
|
39
39
|
<% end -%>
|
40
40
|
<div class="inline">
|
41
|
-
<%%= form.submit class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
41
|
+
<%%= form.submit class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %>
|
42
42
|
</div>
|
43
43
|
<%% end %>
|
@@ -5,6 +5,6 @@
|
|
5
5
|
|
6
6
|
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
7
7
|
|
8
|
-
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
9
|
-
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
8
|
+
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
9
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %>, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
10
10
|
</div>
|