Skip to content

Commit 2278885

Browse files
authored
Merge pull request #110 from phoenixframework/sd-tailwind3to4
add notes for tailwind3/4 compatibility
2 parents dd1725a + f1b13e1 commit 2278885

File tree

2 files changed

+78
-9
lines changed

2 files changed

+78
-9
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## v0.3.0
4+
5+
Support Tailwind v4+. This release drops official support for Tailwind v3.
6+
If you want to continue using Tailwind v3, please pin the `tailwind` dependency to a 0.2 version:
7+
8+
```elixir
9+
{:tailwind, "~> 0.2.0", only: :dev}`
10+
```
11+
312
## v0.2.4 (2024-10-18)
413

514
* Add version check flag

README.md

+69-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ in dev:
1919
```elixir
2020
def deps do
2121
[
22-
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
22+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev}
2323
]
2424
end
2525
```
@@ -30,19 +30,27 @@ then it only needs to be a dev dependency:
3030
```elixir
3131
def deps do
3232
[
33-
{:tailwind, "~> 0.2", only: :dev}
33+
{:tailwind, "~> 0.3", only: :dev}
3434
]
3535
end
3636
```
3737

3838
Once installed, change your `config/config.exs` to pick your
39-
tailwind version of choice:
39+
Tailwind version of choice:
4040

4141
```elixir
4242
config :tailwind, version: "4.0.0"
4343
```
4444

45-
Now you can install tailwind by running:
45+
Note that `:tailwind` 0.3+ supports Tailwind v4+. If you need to use Tailwind v3, use
46+
47+
```
48+
{:tailwind, "~> 0.2.0", only: :dev}
49+
```
50+
51+
instead, and refer to [the README in the 0.2 branch](https://github.com/phoenixframework/tailwind/blob/v0.2/README.md).
52+
53+
Now you can install Tailwind by running:
4654

4755
```bash
4856
$ mix tailwind.install
@@ -56,7 +64,7 @@ you can supply a third party path to the binary the installer wants
5664
$ mix tailwind.install https://people.freebsd.org/~dch/pub/tailwind/v3.2.6/tailwindcss-freebsd-x64
5765
```
5866

59-
And invoke tailwind with:
67+
And invoke Tailwind with:
6068

6169
```bash
6270
$ mix tailwind default
@@ -91,16 +99,18 @@ to the ones configured above. Note profiles must be configured in your
9199

92100
## Adding to Phoenix
93101

94-
To add `tailwind` to an application using Phoenix, you will need Phoenix v1.6+
95-
and the following steps.
102+
Note that applications generated with Phoenix older than 1.8 still use Tailwind v3 by default.
103+
If you're using Tailwind v3 please refer to [the README in the v0.2 branch](https://github.com/phoenixframework/tailwind/blob/v0.2/README.md#adding-to-phoenix)
104+
instead.
96105

97-
First add it as a dependency in your `mix.exs`:
106+
To add Tailwind v4 to an application using Phoenix, first add this package
107+
as a dependency in your `mix.exs`:
98108

99109
```elixir
100110
def deps do
101111
[
102112
{:phoenix, "~> 1.7"},
103-
{:tailwind, "~> 0.2.4", runtime: Mix.env() == :dev}
113+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev}
104114
]
105115
end
106116
```
@@ -165,6 +175,56 @@ right away. It also generates a default configuration file called
165175
when we configured `tailwind` in `config/config.exs`. See
166176
`mix help tailwind.install` to learn more.
167177

178+
## Updating from Tailwind v3 to v4
179+
180+
For a typical Phoenix application, updating from Tailwind v3 to v4 requires the following steps:
181+
182+
1. Update the `:tailwind` library to version 0.3+
183+
184+
```diff
185+
defp deps do
186+
[
187+
- {:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
188+
+ {:tailwind, "~> 0.3", runtime: Mix.env() == :dev},
189+
]
190+
end
191+
```
192+
193+
2. Adjust the configuration to run Tailwind from the root of your repo (or the web app in an umbrella project):
194+
195+
```diff
196+
config :tailwind,
197+
- version: "3.4.13",
198+
+ version: "4.0.0",
199+
default: [
200+
args: ~w(
201+
- --config=tailwind.config.js
202+
- --input=css/app.css
203+
- --output=../priv/static/assets/app.css
204+
+ --config=assets/tailwind.config.js
205+
+ --input=assets/css/app.css
206+
+ --output=priv/static/assets/app.css
207+
),
208+
- cd: Path.expand("../assets", __DIR__)
209+
+ cd: Path.expand("..", __DIR__)
210+
]
211+
```
212+
213+
This allows Tailwind to automatically pick up classes from your project. Tailwind v4 does not require explicit configuration of sources.
214+
215+
3. Adjust the Tailwind imports in your app.css
216+
217+
```diff
218+
-@import "tailwindcss/base";
219+
-@import "tailwindcss/components";
220+
-@import "tailwindcss/utilities";
221+
+@import "tailwindcss";
222+
```
223+
224+
4. Follow the [Tailwind v4 upgrade guide](https://tailwindcss.com/docs/upgrade-guide) to address deprecations.
225+
226+
5. Optional: remove the `tailwind.config.js` and switch to the new CSS based configuration. For more information, see the previously mentioned upgrade guide and the [documentation on functions and directives](https://tailwindcss.com/docs/functions-and-directives).
227+
168228
## License
169229

170230
Copyright (c) 2022 Chris McCord.

0 commit comments

Comments
 (0)