Skip to content

Commit daf448c

Browse files
committed
Add Rebuild Tailwind Bundle For Dev Server as a Rails TIL
1 parent aaddc35 commit daf448c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1560 TILs and counting..._
13+
_1561 TILs and counting..._
1414

1515
See some of the other learning resources I work on:
1616
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -1037,6 +1037,7 @@ See some of the other learning resources I work on:
10371037
- [Query A Single Value From The Database](rails/query-a-single-value-from-the-database.md)
10381038
- [Read In Environment-Specific Config Values](rails/read-in-environment-specific-config-values.md)
10391039
- [Read-Only Models](rails/read-only-models.md)
1040+
- [Rebuild Tailwind Bundle For Dev Server](rails/rebuild-tailwind-bundle-for-dev-server.md)
10401041
- [Remove A Database Column From A Table](rails/remove-a-database-column-from-a-table.md)
10411042
- [Remove The Default Value On A Column](rails/remove-the-default-value-on-a-column.md)
10421043
- [Render An Alternative ActionMailer Template](rails/render-an-alternative-action-mailer-template.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rebuild Tailwind Bundle For Dev Server
2+
3+
If you're using the TailwindCSS gem in your Rails app:
4+
5+
```ruby
6+
# Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]
7+
gem "tailwindcss-rails"
8+
```
9+
10+
you may find that as you add and adjust styles in your views, refreshing the
11+
page doesn't take any styling effects. That is because the tailwind bundle gets
12+
built with just the style rules that were used at the time it was generated.
13+
14+
In development, as we're working, we expect the styles used by our app to
15+
actively changed. And we don't mind a little performance hit to have the bundle
16+
rebuilt. In that case, we can instruct `puma` to _Live Rebuild_ in
17+
`development` with the `tailwindcss` plugin.
18+
19+
```ruby
20+
# config/puma.rb
21+
22+
# Enable TailwindCSS rebuild in development
23+
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
24+
```
25+
26+
This has `rails server` run a watch process in the background that live
27+
rebuilds the bundle.
28+
29+
[source](https://github.com/rails/tailwindcss-rails?tab=readme-ov-file#puma-plugin)

0 commit comments

Comments
 (0)