nhayder's avatar
Level 13

Laravel mix is not complying font awesome properly

this should be easy but yet its not working for me, i'm using laravel 5.8 to build me app and i need to compile font awesome through npm.

the package is already added to the app but after npm run? it looks like font are missing across my app.

this is my app.scss as per fontawesome documentation

// [email protected]
$fa-font-path: "../webfonts";

@import '~@fortawesome/fontawesome-free/scss/fontawesome.scss';
@import '~@fortawesome/fontawesome-free/scss/solid.scss';
@import '~@fortawesome/fontawesome-free/scss/regular.scss';
@import '~@fortawesome/fontawesome-free/scss/brands.scss';

when i run npm run dev i can't see icons on the front end site neither i can find font folder on the public folder.

on chrome devTools i have this error

Failed to load resource: the server responded with a status of 404 (Not Found) 
fa-solid-900.woff2:1 // basically the font is missing ???

// and this error also whitch mean the same
GET http://127.0.0.1:8000/webfonts/fa-solid-900.ttf net::ERR_ABORTED 404 (Not Found)

any ideas on what is going on ???

0 likes
9 replies
rodrigo.pedra's avatar

Does removing (or commenting) this line:

$fa-font-path: "../webfonts";

change the situation?

Also can you open your generated css, must be in './public/css/app.scss, search for any @font-face` and post that rule here?

1 like
nhayder's avatar
Level 13

@rodrigo.pedra thank you for your replay, .. I have commented this

$fa-font-path: "../webfonts";

after the compilation is completed i searched for @font-face and i found 4 of them as expected

@font-face {
  font-family: 'Font Awesome 5 Free';
  font-style: normal;
  font-weight: 900;
  font-display: auto;
  src: url("../webfonts/fa-solid-900.eot");
  src: url("../webfonts/fa-solid-900.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-solid-900.woff2") format("woff2"), url("../webfonts/fa-solid-900.woff") format("woff"), url("../webfonts/fa-solid-900.ttf") format("truetype"), url("../webfonts/fa-solid-900.svg#fontawesome") format("svg");
}

.fa,
.fas {
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
}

/*!
 * Font Awesome Free 5.12.1 by @fontawesome - https://fontawesome.com
 * License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
 */

@font-face {
  font-family: 'Font Awesome 5 Free';
  font-style: normal;
  font-weight: 400;
  font-display: auto;
  src: url("../webfonts/fa-regular-400.eot");
  src: url("../webfonts/fa-regular-400.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-regular-400.woff2") format("woff2"), url("../webfonts/fa-regular-400.woff") format("woff"), url("../webfonts/fa-regular-400.ttf") format("truetype"), url("../webfonts/fa-regular-400.svg#fontawesome") format("svg");
}

.far {
  font-family: 'Font Awesome 5 Free';
  font-weight: 400;
}

/*!
 * Font Awesome Free 5.12.1 by @fontawesome - https://fontawesome.com
 * License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
 */

@font-face {
  font-family: 'Font Awesome 5 Brands';
  font-style: normal;
  font-weight: 400;
  font-display: auto;
  src: url("../webfonts/fa-brands-400.eot");
  src: url("../webfonts/fa-brands-400.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-brands-400.woff2") format("woff2"), url("../webfonts/fa-brands-400.woff") format("woff"), url("../webfonts/fa-brands-400.ttf") format("truetype"), url("../webfonts/fa-brands-400.svg#fontawesome") format("svg");
}

.fab {
  font-family: 'Font Awesome 5 Brands';
  font-weight: 400;
}
nhayder's avatar
Level 13

@rodrigo.pedra just tried to copy webfonts folder to public and i got all icons back ????

what do you think the problem is ????

rodrigo.pedra's avatar
Level 56

Weird, the fonts path should be resolved by the sass compiler.

As a workaround add this line to your webpack.mix.js file:

mix.copyDirectory('node_modules/@fortawesome/fontawesome-free/webfonts', 'public/webfonts');
4 likes
rodrigo.pedra's avatar

Webpack should resolve the sass url imports to local paths. Somehow it is not working.

My last answer tells mix to copy that folder for you so you won't have to remember doing it.

It should keep working, even if later your sass compilation starts working as expected.

1 like
nhayder's avatar
Level 13

@rodrigo.pedra yah thank you it worked and i can see the fonts inside webfonts folder and all fonts on my app are back to live again.

It was definitely a practical work around but i was hoping to fix the compiler instead to copying files by webpack.mix.js

any idea on how to fix this ????

rodrigo.pedra's avatar

No, unfotunately.

I tried locally, my webpack,mix.js is like this:

const mix = require('laravel-mix');

mix.sass('resources/assets/sass/app.scss', 'public/css');

and app.scss is:

// [email protected]

@import '~@fortawesome/fontawesome-free/scss/fontawesome.scss';
@import '~@fortawesome/fontawesome-free/scss/solid.scss';
@import '~@fortawesome/fontawesome-free/scss/regular.scss';
@import '~@fortawesome/fontawesome-free/scss/brands.scss';

An paths are translated correctly, for example:


@font-face {
  font-family: 'Font Awesome 5 Free';
  font-style: normal;
  font-weight: 900;
  font-display: auto;
  src: url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.eot?89e02bae13c9131c7468b1e729339ac1);
  src: url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.eot?89e02bae13c9131c7468b1e729339ac1) format("embedded-opentype"), url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.woff2?55eb2a60e8181f0e68b558c991973bf0) format("woff2"), url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.woff?cdfec5cf5e9840889790bcf2c4042583) format("woff"), url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.ttf?75f38a159982b6bd1704891332d95fa7) format("truetype"), url(/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.svg?0724bb8b89ab6b8b9b7df917b17be0b7) format("svg");
}

maybe it is the mix version, I am using version5.

But don't worry. If in a later update the paths start to be resolved mix will copy the fonts automatically to the ./public/fonts/vendor folder and your app won't break.

1 like

Please or to participate in this conversation.