janp

janp

How to use fonts from bootstrap-icons?

I am using Elixir and Phoenix for more than 5 years and I only built API applications in the past, so I never had the need to care about assets etc. and when I needed them, I always used the CDN-files.

This time I wanted to have a look into this because it is one of the major things I really don’t know anything about. I created a new phoenix application with mix phx.new --no-tailwind. I used --no-tailwind because I know Bootstrap way better than Tailwind.

CSS and JS is working fine, I can use Bootstrap for my application, but I also want to use the bootstrap icons, so I added them via yarn add -D bootstrap-icons.

Here are the most important parts of my application that are somehow related to my issue:

mix.exs

# ...
  def deps do
    [
      # ...
      {:dart_sass, "~> 0.7.0", runtime: Mix.env() == :dev}
    ]
  end

  def aliases do
    [
      # ...
      "assets.setup": ["sass.install --if-missing", "esbuild.install --if-missing"],
      "assets.build": ["sass default", "esbuild default"],
      "assets.deploy": ["sass default --no-source-map --style=compressed", "esbuild default --minify", "phx.digest"]
    ]
  end

# ...

config/config.exs

# ...

config :dart_sass,
  version: "1.61.0",
  default: [
    args: ~w(css/app.scss ../priv/static/assets/app.css),
    cd: Path.expand("../assets", __DIR__)
  ]

assets/package.json

{
  "devDependencies": {
    "@popperjs/core": "^2.11.8",
    "bootstrap": "^5.3.2",
    "bootstrap-icons": "^1.11.1"
  }
}

assets/css/app.scss

// Bootstrap
@import "../node_modules/bootstrap/scss/bootstrap";

// Bootstrap Icons
@import "../node_modules/bootstrap-icons/font/bootstrap-icons";

assets/js/app.js

# ...
import "bootstrap"
# ...

When I now try to access a font, I only get a 404 page :thinking:

http://localhost:4000/assets/fonts/bootstrap-icons.woff2?24e3eb84d0bcaf83d77f904c78ac1f47404 Not Found

I can make it work when copying the fonts to priv/static/assets:

cp -r assets/node_modules/bootstrap-icons/font/fonts priv/static/assets/

But I can’t believe CSS and JS asset management is automated, but for using fonts I need to copy them manually :thinking:

I found some articles that are speaking about fonts, but those were quite old and some extra dependencies I would need to install have already been deprecated, so I am a bit lost :confused:

Maybe someone can enlighten me :slight_smile:

First Post!

yasoob

yasoob

Were you able to figure this out? I encountered a similar issue earlier and was clueless. Would love to hear some input from experienced folks on how to properly make use of an icon font in Phoenix.

Where Next?

Popular in Questions Top

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
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement