Laravel 5.7 + Font Awesome

匿名 (未验证) 提交于 2019-12-03 01:10:02

问题:

I triying to include Font Awesome in Laravel 5.7.

I done this :

1) npm install --save-dev @fortawesome/fontawesome-free --I check the folders in node_modules and all ok

$fa-font-path: "../webfonts";  // Bootstrap @import '~bootstrap/scss/bootstrap'; @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'; 

3) Then :

npm run development -- --watch 

4) And then, I see files in public/fonts/vendor/@fortawesome/fontawesome-free/ But when I go to the browser , the icons looks like this :

回答1:

For Laravel 5.7+ and Font Awesome 5

Run...

npm i @fortawesome/fontawesome-free 

This should now be in your package.json...

// Font Awesome "dependencies": {     "@fortawesome/fontawesome-free": "^5.4.1", 

In /resources/js/bootstrap.js add this line...

require('@fortawesome/fontawesome-free'); 

In /resources/sass/app.scss add this line...

@import "~@fortawesome/fontawesome-free/css/all.css"; 

In /resources/sass/_variables.scss add this line...

$fa-font-path: "../fonts" !default; 

Make sure your webpack.mix.js file has something like this...

const mix = require('laravel-mix');  mix.js('resources/js/app.js', 'public/js')    .sass('resources/sass/app.scss', 'public/css'); 

Lets compile all our assets and produce a production-ready build...

npm run production 

Finally, reference your new CSS & JS files in your layout.

<link type="text/css" rel="stylesheet" href="{{ mix('css/app.css') }}"> <script src="{{ mix('js/app.js') }}"></script> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!