wwaldner

wwaldner

I followed this guide to setup Tailwind on a new phoenix application. Install Tailwind CSS with Phoenix - Tailwind CSS

In dev, any changes to my index.html.heex file automatically builds a new app.css, just like I would expect. However, any classes specified in the heex file are not being processed by tailwind, hence the styles do not work. How do I go about troubleshooting this? It is as if it can’t find, or is not looking for the classes in the heex file, yet the tailwind.config.js is setup to process the heex templates.

tailwind.config.js

let plugin = require('tailwindcss/plugin')

module.exports = {
  content: [
    './js/**/*.js',
    '../lib/*_web.ex',
    '../lib/*_web/**/*.*ex'
  ],
  theme: {
    extend: {},
  },
  plugins: [
    require('@tailwindcss/forms'),
    plugin(({addVariant}) => addVariant('phx-no-feedback', ['&.phx-no-feedback', '.phx-no-feedback &'])),
    plugin(({addVariant}) => addVariant('phx-click-loading', ['&.phx-click-loading', '.phx-click-loading &'])),
    plugin(({addVariant}) => addVariant('phx-submit-loading', ['&.phx-submit-loading', '.phx-submit-loading &'])),
    plugin(({addVariant}) => addVariant('phx-change-loading', ['&.phx-change-loading', '.phx-change-loading &']))
  ]
}

index.html.heex

<h1 class="text-3xl font-bold underline bg-orange-200">
  Hello world!
</h1>

config.exs

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

dev.exs

...
watchers: [
  # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
  esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
  tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
]
...

Showing Posts 1 to 10

tcoopman

tcoopman

Your tailwind config should probably also accept *.heex

Sebb

Sebb

this line does (should) do that.

Maybe there are templates in folders that do not match this glob, maybe _web part missing in the path or a file directly below xxx_web.

For example these template would not be processed by the tailwind compiler.

lib/templates/my-template-tailwind-does-not-see.heex
lib/web/templates/my-other-template-tailwind-does-not-see.heex
lib/my_web/my-other-other-template-tailwind-does-not-see.heex

tcoopman

tcoopman

Didn’t spot the * before the ex on the last line

wwaldner

wwaldner OP

Indeed this is strange. I can run mix tailwind default and it processes the css classes as you would expect. It seems like it is not correctly triggered when a change to the files is detected. My page is reloading when I make a change to the HTML. The browser reloads and the updated HTML is shown, just not the css gubins. Running the mix tailwind default manually does make the classes available in the app.css.

tcoopman

tcoopman

Can you verify that the watcher is actually running?

wwaldner

wwaldner OP

Not sure how to verify that…except that I do know that live-reload happens.

TunkShif

TunkShif

tailwindcss cli watch mode is not working properly in the latest version, so any file changes won’t trigger a css rebuild, see this issue: CLI watch mode not working correctly when using visual studio · Issue #9667 · tailwindlabs/tailwindcss · GitHub
The current workaround is to switch back to version 3.1.8.

arrowsmith

arrowsmith

Did anyone figure out a fix for this? I’m experiencing the same problem and it’s driving me nuts - the tailwind watcher isn’t detecting changes to my app code, so my app.css doesn’t get rebuilt. I have to restart my server every time I add a TW class that isn’t already in app.css.

Downgrading to 3.1.8 didn’t work for me.

If I’m not mistaken then when TW detects changes I should see something like this in my server output:

Rebuilding...

Done in 673ms.

But I only ever see this when the server starts up. It never rebuilds again.

arrowsmith 2 minutes ago

I’m using Phoenix 1.7.9, Elixir 1.15.5, tailwind 0.2.2 (Hex package) and 3.3.5 (actual Tailwind lib). My tailwind.config.js is unchanged from the one generated by mix phx.new.

Anyone have any ideas?

sodapopcan

sodapopcan

How about your config/config.exs Tailwind config? Did you happen change anything there? Have you run mix tailwind default after making changes? Just throwing out ideas here, I’m really not sure what could be wrong.

arrowsmith

arrowsmith

Turns out that I can reproduce this in a minimal Phoenix app:

mix phx.new tailwind_test
cd tailwind_test

That generates an app with Phoenix 1.7.10, tailwind hex package 0.2.2, and tailwind version 3.3.2 as specified in config/config.exs.

Now if I run mix tailwind default --watch and open priv/static/assets/app.css, I can see the generated tailwind utility classes. But if I change an .ex or .heex file in lib/tailwind_test_web, tailwind doesn’t rebuild. The only way I can force it to rebuild is to ctrl+C the mix tailwind default process and start it again.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews