Laravel 5.7 + Font Awesome

你。 提交于 2019-11-26 21:34:22

问题


I'm trying to include the Font Awesome toolkit in Laravel 5.7.

These are the steps I took:

1) Run npm install --save-dev @fortawesome/fontawesome-free

2) Check the folders in node_modules/ and everything looks 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 I ran...

npm run development -- --watch

4) I see files in public/fonts/vendor/@fortawesome/fontawesome-free/.

However, when I go to the browser the icons look like this:


回答1:


Laravel 5.7 through 6.x using Font Awesome 5 (The Right Way)

Build your webpack.mix.js configuration.

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

Install the latest free version of Font Awesome via a package manager like npm.

npm install @fortawesome/fontawesome-free --save

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

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

In your main SCSS file, /resources/sass/app.scss import one or more styles.

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

Compile your assets and produce a minified, production-ready build.

npm run production

Finally, reference your generated CSS file in your Blade template/layout.

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



回答2:


update your webpack.mix.js configuration as below:

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

mix.setPublicPath('public');
mix.setResourceRoot('../');

type 'npm run dev' in your terminal and hit enter



来源:https://stackoverflow.com/questions/52433486/laravel-5-7-font-awesome

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