#Setting up LiveView + Tailwind in Phoenix

5 messages · Page 1 of 1 (latest)

meager egret
#

I'm trying to take a server previously only acting as an API endpoint and adding live view capability. Starting from scratch and copying over is not an option.

Using a fresh project as a template and using the instructions I can find online, I've managed to render a live view page however the tailwind styling is not functioning. I'm at a bit of an impasse troubleshooting where this could be going wrong.

In my mix.exs file I've added:

      {:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},

defp aliases do
    [
      # ...
      "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
      "assets.build": ["tailwind default", "esbuild default"],
      "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"]
    ]
  end

In config.exs:

# Configure esbuild (the version is required)
config :esbuild,
  version: "0.17.11",
  default: [
    args:
      ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
    cd: Path.expand("../assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]

# Configure tailwind (the version is required)
config :tailwind,
  version: "3.3.2",
  default: [
    args: ~w(
      --config=tailwind.config.js
      --input=css/app.css
      --output=../priv/static/assets/app.css
    ),
    cd: Path.expand("../assets", __DIR__)
  ]

I've run mix tailwind.install, my app.css has the following:

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* This file is for your main application CSS */

What can I be missing?

bronze raft
#

Not sure if this is the cause but did you also run esbuild.install?

#

Also just to confirm that you have a tailwind.config.js file?

meager egret
#

I do have a tailwind.config.js file

#

I don't remember if I ran esbuild.install, but I just did and it didn't fix it