Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Install Font Awesome in Laravel Mix

I've tried to install Font Awesome using Laravel Mix but when executing run npm dev I get the following message:

ERROR Failed to compile with 1 errors
error in ./~/font-awesome/scss/font-awesome.scss Module build failed: /** ^ Invalid CSS after "...load the styles": expected 1 selector or at-rule, was "var content = requi" in /var/www/html/blog/node_modules/font-awesome/scss/font-awesome.scss (line 1, column 1)

I removed the comments in the file and tried to change font paths, but it did not solve the problem.

webpack.mix.js

mix.js('resources/assets/js/app.js', 'public/js')    .sass('resources/assets/sass/app.scss', 'public/css')    .copy('node_modules/font-awesome/fonts/', 'public/fonts')    .sass('node_modules/font-awesome/scss/font-awesome.scss', 'public/css')    .version(); 

fontawesome.scss

@import "variables"; @import "mixins"; @import "path"; @import "core"; @import "larger"; @import "fixed-width"; @import "list"; @import "bordered-pulled"; @import "animated"; @import "rotated-flipped"; @import "stacked"; @import "icons"; @import "screen-reader"; 

_variable.scss

// Variables // --------------------------  $fa-font-path:        "../fonts" !default; $fa-font-size-base:   14px !default; $fa-line-height-base: 1 !default; // $fa-font-path:        "//netdna.bootstrapcdn.com/font-awesome/4.7.0/fonts" !default; // for referencing Bootstrap CDN font files directly $fa-css-prefix:       fa !default; $fa-version:          "4.7.0" !default; $fa-border-color:     #eee !default; $fa-inverse:          #fff !default; $fa-li-width:         (30em / 14) !default; // Continue... 
like image 969
Lucas Lopes Avatar asked Apr 17 '17 12:04

Lucas Lopes


People also ask

How do I import fonts into laravel?

First, choose your fonts on fonts.google.com and grab the CSS URL. Next, install the package and publish the config file. Paste the CSS URL in the default font set. // config/google-fonts.

How do I install Font Awesome files?

Include Font Awesome in Your ProjectAdd a link to the /your-path-to-fontawesome/css/all. css file into the <head> of each template or page where you want to use Font Awesome. Just this once, we recommend letting things go to your head.

How do I import Font Awesome into SCSS?

Adding Font Awesome to Your Compile Open your project's scss/variables. scss and edit the $fa-font-path variable to point to where you placed the webfonts folder. $fa-font-path: "../webfonts"; In your main SCSS compile file, import Font Awesome by adding the core styles file, @import "scss/fontawesome.


1 Answers

To install font-awesome you first should install it with npm. So in your project root directory type:

npm install font-awesome --save 

(Of course I assume you have node.js and npm already installed. And you've done npm install in your projects root directory)

Then edit the resources/assets/sass/app.scss file and add at the top this line:

@import "node_modules/font-awesome/scss/font-awesome.scss"; 

Now you can do for example:

npm run dev 

This builds unminified versions of the resources in the correct folders. If you wanted to minify them, you would instead run:

npm run production 

And then you can use the font.

like image 192
Kornel Avatar answered Oct 13 '22 04:10

Kornel