budgie

budgie

How do you format CSS and JavaScript/TypeScript with `mix format`?

I know you can use plugins, but I couldn’t find any in the hex repos for formatting CSS and JS/TS. What’s the recommended solution for this?

First Post!

Eiji

Eiji

Good question. Since I’m working with assets “by hand” I’m also interested. :thinking:

I’m not sure if mix format can or even should handle assets dir. What I’m sure about is that we can create an alias named format and call many aliases/tasks with such alias. One task could use system tools or online services to format code. That’s easy way if you know and especially have installed/used any in past. :+1:

However it would be amazing to have something like esbuild installer to install some formatter. I’m also interested, but additionally I would like to ask for SCSS and SASS as well. :muscle:

Unfortunately I’m worried that most of community is using Tailwind as it’s included by default. :worried:

Most Liked

ibarch

ibarch

For JS, TS and JSON files the modern formatter is Biome. The team behind Biome is still working on CSS support. Until that’s complete, you can format CSS files with Prettier - the legacy tool Biome is intended to replace.
Both of these tools can be installed with npm inside /assets directory and executed with mix, e.g.:

defp aliases do
  [
    "assets.format-js": [
      "cmd --cd assets/ npx @biomejs/biome format scripts/ --write"
    ],
    "assets.format-css": [
      # similar command for Prettier and /styles dir
    ],
    "format-all": ["format", "assets.format-js", "assets.format-css"]
  ]
end

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement