coen.bakker

coen.bakker

Esbuild not flattening nested CSS

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?

Marked As Solved

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

Also Liked

coen.bakker

coen.bakker

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

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.

Last Post!

tj0

tj0

Yuck. Possibly could just be the css itself not being supported by Safari? Sorry, no other ideas. :cry:

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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 36820 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement