Skip to content

Commit 2c509fd

Browse files
author
David Heinemeier Hansson
committed
Clearer separation on webpack v asset pipeline modes
1 parent 4c84a26 commit 2c509fd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22

33
[Tailwind CSS](https://tailwindcss.com) is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
44

5-
Tailwind CSS for Rails makes it easy to use this CSS framework with the asset pipeline. In development mode, the full 3mb+ Tailwind stylsheet is loaded, but in production, only the css classes used by files in `app/views` and `app/helpers` are included.
5+
Tailwind CSS for Rails works with both the asset pipeline and Webpacker.
66

7-
This gem just gives access to the standard Tailwind CSS framework. If you need to customize Tailwind, you will need to have [Webpacker](https://github.com/rails/webpacker) installed. Tailwind will be installed automatically if Webpacker is installed. After this you need to refer to the [TailwindCSS documentation](https://tailwindcss.com/docs/installation#customizing-your-configuration) to customize your tailwind.config.js file.
7+
When use with the asset pipeline, production-mode purging of unused css class names is provided by a Sprockets compressor built into this gem. This compressor ensures that only the css classes used by files in `app/views` and `app/helpers` are included. In development mode, the full 3mb+ Tailwind stylsheet is loaded. In both cases, Tailwind CSS is configured for dark mode, forms, aspect-ratio, typography, and the Inter font. If you need more configuration than that, you'll need to use it with Webpacker.
88

9-
The version of Tailwind included in this gem has been configured for dark mode, forms, aspect-ratio, typography, and the Inter font.
9+
When used with Webpacker, Tailwind CSS is installed as a postCSS processor. Refer to the [TailwindCSS documentation](https://tailwindcss.com/docs/installation#customizing-your-configuration) to customize your tailwind.config.js file.
1010

1111

1212
## Installation
1313

1414
1. Run `./bin/bundle add tailwindcss-rails`
1515
2. Run `./bin/rails tailwindcss:install` (on a fresh Rails application)
1616

17-
The last option adds the purger compressor to `config/environments/production.rb`. This ensures that when `assets:precompile` is called during deployment that the unused class names are not included in the tailwind output css used by the app. It also adds a `stylesheet_link_tag "tailwind"` and `stylesheet_link_tag "inter-font"` to your `app/views/application.html.erb` file.
17+
When run on an app using the just the asset pipeline, the last step adds the purger compressor to `config/environments/production.rb`. This ensures that when `assets:precompile` is called during deployment that the unused class names are not included in the tailwind output css used by the app. It also adds a `stylesheet_link_tag "tailwind"` and `stylesheet_link_tag "inter-font"` to your `app/views/application.html.erb` file.
1818

1919
You can do these things yourself, if you've changed the default setup.
2020

2121
Note: You should ensure to delete `app/assets/stylesheets/scaffold.scss` that Rails adds after running a scaffold command. This stylesheet will interfere with Tailwind's reset of base styles.
2222

23+
When run on an app using Webpacker, the last step adds the npm dependencies for Tailwind CSS, configures postCSS, and generates a app/javascript/stylesheets/application.scss file as the default for using Tailwind.
24+
25+
2326
## Purging in production
2427

25-
The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So this gem includes a Sprockets compressor that purges the tailwind file from all those unused classes.
28+
The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So this gem includes a Sprockets compressor that purges the tailwind file from all those unused classes when Tailwind CSS for Rails is used with the asset pipeline.
2629

2730
This compressor is currently not compatible with the default Sprockets cache system due to the fact its output depends on files outside of Sprockets (all the files observed for utility class name usage), so this cache is disabled in production. If you need to disable it in other deployed environments, add the following to that environment configuration file:
2831

@@ -35,7 +38,7 @@ end
3538

3639
## Configuration
3740

38-
If you need to customize what files are searched for class names, you need to replace the compressor line with something like:
41+
If you need to customize what files are searched for class names when using the asset pipeline, you need to replace the compressor line with something like:
3942

4043
```ruby
4144
config.assets.css_compressor = Tailwindcss::Compressor.new(files_with_class_names: Rails.root.glob("app/somehere/**/*.*"))

0 commit comments

Comments
 (0)