hq1

hq1

Hi,

I am completely clueless when it comes to the whole static assets building pipeline. That’s probably the most overwhelming programming experience in my career thus far :joy:

Seriously though, can anyone please share a snippet of things I need to add to have FontAwesome icons available in a phoenix app?

I’m using Phoenix 1.4.0 so I guess that’s webpack then, plus I do npm install in assets directory to get the priv contents built. Everything is pretty much at mix phx.new defaults. Pls send halp.

Showing Posts 1 to 10

hauleth

hauleth

You enter assets directory and then follow NPM instructions. That is it. Phoenix assets pipeline is exactly the same way as any other webpack project with specific build directory (../priv/static) and that is all.

adrianrl

adrianrl

Hi, when it comes to icons, fonts or heavy dependencies it’s a good idea to serve those assets using their respective CDNs, so I’d rather add a simple link tag to include Font Awesome. You should only serve by yourself those dependencies that you want to customize.

hq1

hq1 OP

You enter assets directory and then follow NPM instructions . That is it.

I wish. Nothing related to font awesome ends up in priv/static after doing just that.

“Same way as any other webpack project” means nothing to me unfortunately.

hq1

hq1 OP

That makes sense, I’ll see if I can just put those pre-built assets on S3 due to privacy concerns.

hauleth

hauleth

Have you restarted your application? It need to be rebuilt after the fact.

MrDoops

MrDoops

You might need something like File Loader to manage the kinds of assets FontAwesome provides. This guide seems to go over using Font Awesome and File Loader.

kokolegorille

kokolegorille

I have this loader for fonts in my webpack.config.js, in the modules/rules section

      // Load fonts
      {
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?(\?.*$|$)/,
        use: 'url-loader?&limit=10000&name=/fonts/[name].[ext]',
      },
      {
        test: /\.(eot|ttf|otf)?(\?.*$|$)/,
        loader: 'file-loader?&limit=10000&name=/fonts/[name].[ext]',
      },

Then in app.js, I load app.scss, and in app.scss, I load fontawesome, something like this…

@import '../../node_modules/font-awesome/css/font-awesome.css';

But for this to work, I added following dev dependencies,

node-sass, sass-loader, file-loader, url-loader.

You might show your webpack.config.js, and your package.json.

eahanson

eahanson

Another option is to download individual font awesome icons as SVGs into assets/static/images and them emit them in your templates or views with Phoenix Inline SVG.

If you only want a few icons, this can reduce the size of your responses and doesn’t involve any webpack stuff. Caveats: some older browsers have issues with SVG, and every time you want a new icon, you have to download it and add it to your assets directory.

hq1

hq1 OP

Thank you, that worked!

belgoros

belgoros

Navigate to your phoenix app assets directory:

cd your_app/assets

Install free edition of fontawesome as explained here:

npm install --save-dev @fortawesome/fontawesome-free

You will see package.json updated with a new entry:

..
"devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@fortawesome/fontawesome-free": "^5.9.0",
...

You will have to install file-loader package as well: npm install file-loader.

Then modify webpack.config.js to be able to copy awesome fonts and extract SCSS files:

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.(css|sass|scss)$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
      },
      {
        test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
        use: [{
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: '../fonts'
          }
        }]
      }
    ]
  },
...

Next, modify your app.scss file as follows (I also use Bootrstrap, so remove the related import if you don’t use it):

@import "custom";
@import "~bootstrap/scss/bootstrap";
@import "~@fortawesome/fontawesome-free/scss/fontawesome";
@import "~@fortawesome/fontawesome-free/scss/regular";
@import "~@fortawesome/fontawesome-free/scss/solid";
@import "~@fortawesome/fontawesome-free/scss/brands";

And finally, my _custom.scss file (remove $primary containing line, it is for Bootrstap override):

/* Boostrap overrides */

$primary: #F92653;

/* Fontawesome 5 config */

$fa-font-path: "~@fortawesome/fontawesome-free/webfonts"

Hope, this helps.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews