fdeage

fdeage

Official, up-to-date boilerplate for `tailwind` and `esbuild`?

Hi there,

I am trying to migrate a mid-size project from Phoenix 1.5.13 to 1.6.6. The Phoenix/LiveView part went smoothly, but after two days I can’t get my asset pipeline to work:

  • tailwind and esbuild seem to cancel one another: I can have the “tailwind CSS” working or the “esbuild CSS” working, but not both ;

  • It seems I can’t import external CSS files (font-awesome, flatpickr, etc.) from a CSS file managed by tailwind ;

  • Also, a lot of other assets (images, etc.) are not compiled anymore.

So I have a few questions for the community:

  • Should I remove import css from "../css/app.css"; from my app.js? (some answers say yes, others say no)

  • Why do I have to move my static assets from assets/static to priv/static?

  • In what dir should I put my external CSS? Do the import from app.css still work?

  • In config.exs, should esbuild default --minify come first, or tailwind default --minify? If it doesn’t matter because there are two separate pipelines, does it even mean I have two different CSS files to import (one from priv/static/assets, the other from priv/static/css?

  • Do I have to keep npm/yarn to manage my JS dependencies?

  • Do I need to keep using postcss?

  • In app.css, should I use the @import "tailwindcss/base"; syntax, or the @tailwind base; one?

I have been navigating issues, PR and elixirforum answers for a while, so any help on any of the above questions would be greatly appreciated :slight_smile:

Marked As Solved

KristerV

KristerV

Your tailwind config should look something like this:

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

As you can see app.css is already referenced there so no need to have it in app.js.

Webpack conf has one approach, esbuild has another, but really it’s up to you to configure. The new consensus seems to be (logically thinking) that files that don’t get transformed anyway have no reason to start in one place and end in another. And static files are the ones that aren’t compiled or anything.

If you want to import CSS files you should have them in assets/css/, but i haven’t yet had to import them so ot going to assume i know how to import.

I usually put tailwind first, but I’m not sure if it makes a difference.

if you have dependencies in package.json, then yes you need all of node.js still. i try to avoid it, but Alpine.JS for example requires it.

I don’t seem to have it installed. I’m using Tailwind.

The ‘official’ Tailwind integration uses @import "tailwindcss/base";

The fastest way to get a Tailwind LiveView project up and most ‘official’ way is

mix local.hex
mix archive.install hex phx_new
mix phx.new app_name --live --binary-id
mix phx.gen.auth Accounts User users
# https://github.com/phoenixframework/tailwind

That repo is semi-automated and I suggest you go through the steps with a new project, commit every step. This way you’ll understand better what is the current accepted standard and how things work.

I included the auth stuff just because it’s a common need and can be part of the boilerplate.

Disclaimer: I’m still a noob with bad memory. Especially the npm part I’m not fully sure of, even though I have projects with and without package.json.

Also Liked

KristerV

KristerV

Using Routes is indeed a great idea. If I understood correctly you don’t like having that string as the second argument and I don’t like it either. I guess one way of solving this would be to add multiple CSS files to the tailwind conf.

Not sure how to @import though. Let me know if you find out :slight_smile:

In this case you need to be more specific either with showing us what files are generated there or showing us your configurations in terms of generated outputs.

My guess would be that you’re still using the old system, where more files were moved. Check your conf that you only move the app.js (esbuild) and app.css (tailwind) files.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement