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...
To install font-awesome you first should install it with npm. So in your project root directory type:
(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:Now you can do for example:
This builds unminified versions of the resources in the correct folders. If you wanted to minify them, you would instead run:
And then you can use the font.
For Laravel >= 5.5
npm install font-awesome --save
@import "~font-awesome/scss/font-awesome.scss";
inresources/assets/saas/app.scss
npm run dev
(ornpm run watch
or evennpm run production
)Try in your webpack.mix.js to add the '*'
For Font Awesome 5(webfont with css) and Laravel mixin add package for font awesome 5
And import font awesome scss in app.scss or your custom scss file
compile your assets
npm run dev
ornpm run production
and include your compiled css into layoutI am using Laravel 5.5.14 and none of the above worked for me. So here are the steps I did to make it work.
1.Install font-awesome by using npm:
2.Move the fonts to your public directory by adding this line in your
webpack.mixin.js
3.Open your app.scss to specify the path of the fonts in your node_modules and which relative path to use for compilation:
For Laravel 5.6 and Font Awesome 5
Build your webpack.mix.js configuration.
Install Font Awesome.
This line should now be in your package.json.
In /resources/sass/app.scss import one or more styles.
Let's compile all our assets and produce a production-ready build.
Finally, reference your new CSS file in your layout.