|
2 | 2 |
|
3 | 3 | [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.
|
4 | 4 |
|
5 |
| -This gem gives access to the standard Tailwind CSS framework configured for dark mode, forms, aspect-ratio, typography, and the Inter font via the asset pipeline using Sprockets (and soon [Propshaft](https://github.com/rails/propshaft)). |
| 5 | +This gem wraps [the standalone executable version](https://tailwindcss.com/blog/standalone-cli) of the Tailwind CSS 3 framework. These executables are platform specific, but the correct gem will automatically be picked for your platform. Supported platforms are Linux x64, macOS arm64, macOS x64, and Windows x64. |
6 | 6 |
|
7 |
| -If you need to customize Tailwind, you will need to install it under a full JavaScript bundling setup, such as [cssbundling-rails](https://github.com/rails/cssbundling-rails). This gem was specifically designed not to require a Node.js environment. If you're already using such an environment, you won't need this gem. |
| 7 | +You can customize the Tailwind build through the `config/tailwind.config.js` file, just like you would if Tailwind was running in a traditional node installation. All the first-party plugins are supported. |
8 | 8 |
|
9 |
| -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 7mb+ Tailwind stylesheet is loaded. |
| 9 | +The installer will create your 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. When you run `rails tailwindcss:build`, this 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 (the installer automatically configures this, alongside the Inter font as well). |
10 | 10 |
|
| 11 | +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. |
11 | 12 |
|
12 |
| -## Installation |
13 |
| - |
14 |
| -1. Run `./bin/bundle add tailwindcss-rails` |
15 |
| -2. Run `./bin/rails tailwindcss:install` |
16 |
| - |
17 |
| -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/layouts/application.html.erb` file. |
18 |
| - |
19 |
| -You can do these things yourself, if you've changed the default setup. |
20 |
| - |
21 |
| - |
22 |
| -## Purging in production |
23 |
| - |
24 |
| -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 the Sprockets compressor included in this gem is used to purge the tailwind file from all those unused classes for production. |
25 |
| - |
26 |
| -Note: 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: |
| 13 | +When you're developing your application, you want to run Tailwind in watch mode, so changes are automatically reflected in the generated CSS output. You can do this either by running `rails tailwindcss:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to starts both the Tailwind watch process and the rails server in development mode. |
27 | 14 |
|
28 |
| -```ruby |
29 |
| -Rails.application.config.assets.configure do |env| |
30 |
| - env.cache = ActiveSupport::Cache.lookup_store(:null_store) |
31 |
| -end |
32 |
| -``` |
33 | 15 |
|
| 16 | +## Installation |
34 | 17 |
|
35 |
| -## Configuration |
36 |
| - |
37 |
| -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: |
38 |
| - |
39 |
| -```ruby |
40 |
| - config.assets.css_compressor = Tailwindcss::Compressor.new(files_with_class_names: Rails.root.glob("app/somewhere/**/*.*")) |
41 |
| -``` |
42 |
| - |
43 |
| -By default, the CSS purger will only operate on the tailwind css file included with this gem. If you want to use it more broadly: |
44 |
| - |
45 |
| -```ruby |
46 |
| - config.assets.css_compressor = Tailwindcss::Compressor.new(only_purge: %w[ tailwind and_my_other_css_file ]) |
47 |
| -``` |
48 |
| - |
49 |
| - |
50 |
| -## Tailwind versions |
51 |
| - |
52 |
| -The Tailwind CSS main file that's being used before purging consists of these versions: |
| 18 | +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: |
53 | 19 |
|
54 |
| -* @tailwindcss/aspect-ratio 0.2.1 |
55 |
| -* @tailwindcss/forms 0.3.3 |
56 |
| -* @tailwindcss/typography 0.4.1 |
57 |
| -* autoprefixer 10.3.1 |
58 |
| -* tailwindcss 2.2.15 |
| 20 | +1. Run `./bin/bundle add tailwindcss-rails` |
| 21 | +2. Run `./bin/rails tailwindcss:install` |
59 | 22 |
|
60 | 23 |
|
61 |
| -## Compatibility with Tailwind 3.0 |
| 24 | +## Building in production |
62 | 25 |
|
63 |
| -This gem is not yet compatible with the JIT approach taken with Tailwind 3.0. We're working with the team on an approach that would bring compatibility, but at the moment you'd need to use [cssbundling-rails](https://github.com/rails/cssbundling-rails/) (and thus bring Node into your app) in order to use 3.0. |
| 26 | +The `tailwindcss:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Tailwind output will be generated. |
64 | 27 |
|
65 | 28 |
|
66 | 29 | ## Conflict with sassc-rails
|
|
0 commit comments