Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update tailwind to version 4.0.0 #5990

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions guides/mix_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ And then `assets/` which should look similar to this:

```console
├── css
│   └── app.css
│   ├── app.css
│   └── tailwind_heroicons.js
├── js
│   └── app.js
├── tailwind.config.js
└── vendor
└── topbar.js
```
Expand Down
2 changes: 1 addition & 1 deletion installer/lib/phx_new/single.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Phx.New.Single do
template(:css, [
{:eex, :web,
"phx_assets/app.css": "assets/css/app.css",
"phx_assets/tailwind.config.js": "assets/tailwind.config.js"}
"phx_assets/tailwind_heroicons.js": "assets/css/tailwind_heroicons.js"}
])

template(:js, [
Expand Down
15 changes: 12 additions & 3 deletions installer/templates/phx_assets/app.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
/* See the Tailwind configuration guide for advanced usage
https://tailwindcss.com/docs/configuration */

@import "tailwindcss";
@plugin "@tailwindcss/forms";
@plugin "./tailwind_heroicons.js";
@variant phx-click-loading ([".phx-click-loading&", ".phx-click-loading &"]);
@variant phx-submit-loading ([".phx-submit-loading&", ".phx-submit-loading &"]);
@variant phx-change-loading ([".phx-change-loading&", ".phx-change-loading &"]);
@theme {
--color-brand: "#FD4F00",
}

/* This file is for your main application CSS */
74 changes: 0 additions & 74 deletions installer/templates/phx_assets/tailwind.config.js

This file was deleted.

42 changes: 42 additions & 0 deletions installer/templates/phx_assets/tailwind_heroicons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const plugin = require("tailwindcss/plugin")
const fs = require("fs")
const path = require("path")

module.exports = plugin(function({matchComponents, theme}) {
let iconsDir = path.join(__dirname, "../..<%= if @in_umbrella, do: "/../.." %>/deps/heroicons/optimized")
let values = {}
let icons = [
["", "/24/outline"],
["-solid", "/24/solid"],
["-mini", "/20/solid"],
["-micro", "/16/solid"]
]
icons.forEach(([suffix, dir]) => {
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
let name = path.basename(file, ".svg") + suffix
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
})
})
matchComponents({
"hero": ({name, fullPath}) => {
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
let size = theme("spacing.6")
if (name.endsWith("-mini")) {
size = theme("spacing.5")
} else if (name.endsWith("-micro")) {
size = theme("spacing.4")
}
return {
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
"-webkit-mask": `var(--hero-${name})`,
"mask": `var(--hero-${name})`,
"mask-repeat": "no-repeat",
"background-color": "currentColor",
"vertical-align": "middle",
"display": "inline-block",
"width": size,
"height": size
}
}
}, {values})
}
9 changes: 4 additions & 5 deletions installer/templates/phx_single/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ config :esbuild,

# Configure tailwind (the version is required)
config :tailwind,
version: "3.4.3",
version: "4.0.0-beta.3",
<%= @app_name %>: [
args: ~w(
--config=tailwind.config.js
--input=css/app.css
--output=../priv/static/assets/app.css
--input=assets/css/app.css
--output=priv/static/assets/app.css
),
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>/assets", __DIR__),
cd: Path.expand("..<%= if @in_umbrella, do: "/apps/#{@app_name}" %>", __DIR__),
]<% end %>

# Configures Elixir's Logger
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_single/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule <%= @app_module %>.MixProject do
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
{:tailwind, github: "leifmetcalf/tailwind", branch: "tailwind-v4", runtime: Mix.env() == :dev},
{:heroicons,
github: "tailwindlabs/heroicons",
tag: "v2.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ config :esbuild,

# Configure tailwind (the version is required)
config :tailwind,
version: "3.4.3",
version: "4.0.0-beta.3",
<%= @web_app_name %>: [
args: ~w(
--config=tailwind.config.js
--input=css/app.css
--output=../priv/static/assets/app.css
--input=assets/css/app.css
--output=priv/static/assets/app.css
),
cd: Path.expand("../apps/<%= @web_app_name %>/assets", __DIR__)
cd: Path.expand("../apps/<%= @web_app_name %>", __DIR__)
]<% end %>
2 changes: 1 addition & 1 deletion installer/templates/phx_umbrella/apps/app_name_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule <%= @web_namespace %>.MixProject do
{:floki, ">= 0.30.0", only: :test},<% end %><%= if @dashboard do %>
{:phoenix_live_dashboard, "~> 0.8.3"},<% end %><%= if @javascript do %>
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},<% end %><%= if @css do %>
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
{:tailwind, github: "leifmetcalf/tailwind", branch: "tailwind-v4", runtime: Mix.env() == :dev},
{:heroicons,
github: "tailwindlabs/heroicons",
tag: "v2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
width, height, and background color classes.

Icons are extracted from the `deps/heroicons` directory and bundled within
your compiled app.css by the plugin in your `assets/tailwind.config.js`.
your compiled app.css by the plugin in `assets/css/tailwind_heroicons.js`.

## Examples

Expand Down
5 changes: 0 additions & 5 deletions installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ defmodule Mix.Tasks.Phx.NewTest do
# tailwind
assert_file("phx_blog/assets/css/app.css")

assert_file("phx_blog/assets/tailwind.config.js", fn file ->
assert file =~ "phx_blog_web.ex"
assert file =~ "phx_blog_web/**/*.*ex"
end)

refute File.exists?("phx_blog/priv/static/assets/app.css")
refute File.exists?("phx_blog/priv/static/assets/app.js")
assert File.exists?("phx_blog/assets/vendor")
Expand Down
5 changes: 0 additions & 5 deletions installer/test/phx_new_umbrella_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
assert_file(web_path(@app, ".gitignore"), ~r/\n$/)
assert_file(web_path(@app, "assets/css/app.css"))

assert_file(web_path(@app, "assets/tailwind.config.js"), fn file ->
assert file =~ "phx_umb_web.ex"
assert file =~ "phx_umb_web/**/*.*ex"
end)

assert_file(web_path(@app, "priv/static/favicon.ico"))

refute File.exists?(web_path(@app, "priv/static/assets/app.css"))
Expand Down
11 changes: 0 additions & 11 deletions installer/test/phx_new_web_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,4 @@ defmodule Mix.Tasks.Phx.New.WebTest do
assert_received {:mix_shell, :info, ["Start your Phoenix app" <> _]}
end
end

test "app_name is included in tailwind config" do
in_tmp_umbrella_project "new with defaults", fn ->
Mix.Tasks.Phx.New.Web.run(["testweb"])

assert_file "testweb/assets/tailwind.config.js", fn file ->
assert file =~ "testweb.ex"
assert file =~ "testweb/**/*.*ex"
end
end
end
end
4 changes: 2 additions & 2 deletions integration_test/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ config :phoenix, :json_library, Jason

config :swoosh, api_client: false

config :tailwind, :version, "3.4.3"
config :tailwind, :version, "4.0.0-beta.3"

config :phoenix_live_view, enable_expensive_runtime_checks: true
config :phoenix_live_view, enable_expensive_runtime_checks: true
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.live/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
width, height, and background color classes.

Icons are extracted from the `deps/heroicons` directory and bundled within
your compiled app.css by the plugin in your `assets/tailwind.config.js`.
your compiled app.css by the plugin in `assets/css/tailwind_heroicons.js`.

## Examples

Expand Down
Loading