Skip to content

Commit 59e1743

Browse files
committed
Update tailwind to version 4.0.0
1 parent 77ce927 commit 59e1743

File tree

15 files changed

+72
-118
lines changed

15 files changed

+72
-118
lines changed

guides/mix_tasks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ And then `assets/` which should look similar to this:
419419

420420
```console
421421
├── css
422-
│   └── app.css
422+
│   ├── app.css
423+
│   └── tailwind_heroicons.js
423424
├── js
424425
│   └── app.js
425-
├── tailwind.config.js
426426
└── vendor
427427
└── topbar.js
428428
```

installer/lib/phx_new/single.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule Phx.New.Single do
7070
template(:css, [
7171
{:eex, :web,
7272
"phx_assets/app.css": "assets/css/app.css",
73-
"phx_assets/tailwind.config.js": "assets/tailwind.config.js"}
73+
"phx_assets/tailwind_heroicons.js": "assets/css/tailwind_heroicons.js"}
7474
])
7575

7676
template(:js, [

installer/templates/phx_assets/app.css

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
@import "tailwindcss/base";
2-
@import "tailwindcss/components";
3-
@import "tailwindcss/utilities";
1+
/* See the Tailwind configuration guide for advanced usage
2+
https://tailwindcss.com/docs/configuration */
3+
4+
@import "tailwindcss";
5+
@plugin "@tailwindcss/forms";
6+
@plugin "./tailwind_heroicons.js";
7+
@variant phx-click-loading ([".phx-click-loading&", ".phx-click-loading &"]);
8+
@variant phx-submit-loading ([".phx-submit-loading&", ".phx-submit-loading &"]);
9+
@variant phx-change-loading ([".phx-change-loading&", ".phx-change-loading &"]);
10+
@theme {
11+
--color-brand: "#FD4F00",
12+
};
413

514
/*
615
* Make LiveView wrapper divs transparent for layout.

installer/templates/phx_assets/tailwind.config.js

-75
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const plugin = require("tailwindcss/plugin")
2+
const fs = require("fs")
3+
const path = require("path")
4+
5+
module.exports = plugin(function({matchComponents, theme}) {
6+
let iconsDir = path.join(__dirname, "../..<%= if @in_umbrella, do: "/../.." %>/deps/heroicons/optimized")
7+
let values = {}
8+
let icons = [
9+
["", "/24/outline"],
10+
["-solid", "/24/solid"],
11+
["-mini", "/20/solid"],
12+
["-micro", "/16/solid"]
13+
]
14+
icons.forEach(([suffix, dir]) => {
15+
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
16+
let name = path.basename(file, ".svg") + suffix
17+
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
18+
})
19+
})
20+
matchComponents({
21+
"hero": ({name, fullPath}) => {
22+
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
23+
content = encodeURIComponent(content)
24+
let size = theme("spacing.6")
25+
if (name.endsWith("-mini")) {
26+
size = theme("spacing.5")
27+
} else if (name.endsWith("-micro")) {
28+
size = theme("spacing.4")
29+
}
30+
return {
31+
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
32+
"-webkit-mask": `var(--hero-${name})`,
33+
"mask": `var(--hero-${name})`,
34+
"mask-repeat": "no-repeat",
35+
"background-color": "currentColor",
36+
"vertical-align": "middle",
37+
"display": "inline-block",
38+
"width": size,
39+
"height": size
40+
}
41+
}
42+
}, {values})
43+
})

installer/templates/phx_single/config/config.exs

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ config :esbuild,
4545

4646
# Configure tailwind (the version is required)
4747
config :tailwind,
48-
version: "3.4.3",
48+
version: "4.0.3",
4949
<%= @app_name %>: [
5050
args: ~w(
51-
--config=tailwind.config.js
52-
--input=css/app.css
53-
--output=../priv/static/assets/app.css
51+
--input=assets/css/app.css
52+
--output=priv/static/assets/app.css
5453
),
55-
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>/assets", __DIR__),
54+
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>", __DIR__),
5655
]<% end %>
5756

5857
# Configures Elixir's Logger

installer/templates/phx_single/mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule <%= @app_module %>.MixProject do
4747
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
4848
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
4949
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
50-
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
50+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev},
5151
{:heroicons,
5252
github: "tailwindlabs/heroicons",
5353
tag: "v2.1.1",

installer/templates/phx_umbrella/apps/app_name_web/config/config.exs

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ config :esbuild,
2929

3030
# Configure tailwind (the version is required)
3131
config :tailwind,
32-
version: "3.4.3",
32+
version: "4.0.3",
3333
<%= @web_app_name %>: [
3434
args: ~w(
35-
--config=tailwind.config.js
36-
--input=css/app.css
37-
--output=../priv/static/assets/app.css
35+
--input=assets/css/app.css
36+
--output=priv/static/assets/app.css
3837
),
39-
cd: Path.expand("../apps/<%= @web_app_name %>/assets", __DIR__)
38+
cd: Path.expand("../apps/<%= @web_app_name %>", __DIR__)
4039
]<% end %>

installer/templates/phx_umbrella/apps/app_name_web/mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule <%= @web_namespace %>.MixProject do
4545
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
4646
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
4747
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
48-
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
48+
{:tailwind, "~> 0.3", runtime: Mix.env() == :dev},
4949
{:heroicons,
5050
github: "tailwindlabs/heroicons",
5151
tag: "v2.1.1",

installer/templates/phx_web/components/core_components.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
520520
width, height, and background color classes.
521521
522522
Icons are extracted from the `deps/heroicons` directory and bundled within
523-
your compiled app.css by the plugin in your `assets/tailwind.config.js`.
523+
your compiled app.css by the plugin in `assets/css/tailwind_heroicons.js`.
524524
525525
## Examples
526526

installer/test/phx_new_test.exs

-5
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ defmodule Mix.Tasks.Phx.NewTest do
154154
# tailwind
155155
assert_file("phx_blog/assets/css/app.css")
156156

157-
assert_file("phx_blog/assets/tailwind.config.js", fn file ->
158-
assert file =~ "phx_blog_web.ex"
159-
assert file =~ "phx_blog_web/**/*.*ex"
160-
end)
161-
162157
refute File.exists?("phx_blog/priv/static/assets/app.css")
163158
refute File.exists?("phx_blog/priv/static/assets/app.js")
164159
assert File.exists?("phx_blog/assets/vendor")

installer/test/phx_new_umbrella_test.exs

-5
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,6 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
183183
assert_file(web_path(@app, ".gitignore"), ~r/\n$/)
184184
assert_file(web_path(@app, "assets/css/app.css"))
185185

186-
assert_file(web_path(@app, "assets/tailwind.config.js"), fn file ->
187-
assert file =~ "phx_umb_web.ex"
188-
assert file =~ "phx_umb_web/**/*.*ex"
189-
end)
190-
191186
assert_file(web_path(@app, "priv/static/favicon.ico"))
192187

193188
refute File.exists?(web_path(@app, "priv/static/assets/app.css"))

installer/test/phx_new_web_test.exs

-11
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,4 @@ defmodule Mix.Tasks.Phx.New.WebTest do
6363
assert_received {:mix_shell, :info, ["Start your Phoenix app" <> _]}
6464
end
6565
end
66-
67-
test "app_name is included in tailwind config" do
68-
in_tmp_umbrella_project "new with defaults", fn ->
69-
Mix.Tasks.Phx.New.Web.run(["testweb"])
70-
71-
assert_file "testweb/assets/tailwind.config.js", fn file ->
72-
assert file =~ "testweb.ex"
73-
assert file =~ "testweb/**/*.*ex"
74-
end
75-
end
76-
end
7766
end

integration_test/config/config.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ config :phoenix, :json_library, Jason
44

55
config :swoosh, api_client: false
66

7-
config :tailwind, :version, "3.4.3"
7+
config :tailwind, :version, "4.0.3"
88

9-
config :phoenix_live_view, enable_expensive_runtime_checks: true
9+
config :phoenix_live_view, enable_expensive_runtime_checks: true

priv/templates/phx.gen.live/core_components.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
520520
width, height, and background color classes.
521521
522522
Icons are extracted from the `deps/heroicons` directory and bundled within
523-
your compiled app.css by the plugin in your `assets/tailwind.config.js`.
523+
your compiled app.css by the plugin in `assets/css/tailwind_heroicons.js`.
524524
525525
## Examples
526526

0 commit comments

Comments
 (0)