coen.bakker

coen.bakker

I’ve been using nested CSS but I need to support older browsers. My Phoenix app uses the default Esbuild setup, so I looked for support for unnesting CSS.

The Esbuild 0.17.14 release notes mentions CSS flattening.

I cannot seem to get it to work in my Phoenix app, though.

I changed the Esbuild installer to the latest version and added the --target tag to the build statement.

  defp deps do
    [
      {:esbuild, "~> 0.8.1", runtime: Mix.env() == :dev},
    ]
  end
  defp aliases do
    [
      "assets.build": ["esbuild default --target=#{build_target()}"],
      "assets.deploy": ["esbuild default --minify --target=#{build_target()}", "phx.digest"]
    ]
  end

  defp build_target(), do: "es2016,chrome88,edge109,firefox115,safari11"

However, when I run the build, the generated CSS is still nested.

Is the Esbuild installer behind, maybe? Or am I missing something else?

Showing Posts 1 to 10

hubertlepicki

hubertlepicki

this is because Elixir packate :esbuild only ships with 0.17.11 version of esbuild, and you need at lesast mentioned 0.17.14:

https://github.com/phoenixframework/esbuild/blob/v0.8.1/lib/esbuild.ex#L3C21-L3C27

hubertlepicki

hubertlepicki

Looking at that library source, it appears you can force the version you need with:

config :esbuild, :version, "0.17.14"

and then running mix esbuild.install

coen.bakker

coen.bakker OP

Thank you.

I have changed the config to this.

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

I set the version to 0.19.11 because I noticed some changes to how nested CSS is parsed in versions after 0.17.14.

I also included import '../css/app.css'; in my js/app.js after reading the Esbuild docs about CSS, because otherwise the CSS was still not flattened. Not sure why.

coen.bakker

coen.bakker OP

Actually, there was some more unexpected behaviour, even with import '../css/app.css';.

It seems to do with the fact that I still had Tailwind installed and configured. Did a quick test and seems like removing Tailwind solves the problem.

TwistingTwists

TwistingTwists

So then you don’t need taliwind, is it?

Only esbuild is sufficient?

coen.bakker

coen.bakker OP

I tried Tailwind. I wanted to give it a fair shot. At this point I don’t want to use it for my projects. But I’ll continue keeping an eye on it :slight_smile:.

tj0

tj0

I’ve used this to flatten in my configuration. Not using taliwind though.

config :esbuild,
  version: "0.17.18",
  default: [
    args: ~w(js/app.js --bundle --target=es2016,chrome58 --outdir=../priv/static/assets --external:*.woff2 --external:*.svg),
    cd: Path.expand("../assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]

coen.bakker

coen.bakker OP

Ty for your message on Fly.io.

In case someone is interested, on Fly.io I asked “Can I use Esbuild version 0.19.11 instead of 0.17.11 with Phoenix LiveView?”.

This was after I successfully flattened the nested CSS in local development, after the help in this Elixir Forum topic. In production with Fly.io it did not work. Not yet, at least. Also after trying version 0.17.18.

tj0

tj0

Did you try with the lower targets?

`--target=es2016,chrome58`

Edit: Ah, re-read this. If it successfully worked in dev and not in prod, there must a difference in the esbuild configuration between the two environments?

coen.bakker

coen.bakker OP

Actually, now it does flatten. This was indeed the change I made. Which is a head scratcher, since setting --target=es2017,chrome88 did work locally.

Still get super weird styling on iOS on real iPhones and iPads… Must be something else going on then, besides the nested CSS.

Confused at this point. :sweat_smile: But I’ll keep trying to figure out what is going on.

Edit. On Xcode’s Simulator it does work on iOS.

Where Next? Top

Trending in Questions Top

water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
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
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews