glyphicons not showing with sass bootstrap integration
Asked Answered
F

14

14

I used this tutorial to integrate bootstrap in my project:

https://laravel-news.com/2015/10/setup-bootstrap-sass-with-laravel-elixir/

This places an app.css file in the css folder. However if I try to use glyphicons they don't show up. So I tried to modify the elixir file like this:

    elixir(function(mix) {

    mix.sass('app.scss')
        .browserify('app.js')
        .copy('node_modules/bootstrap-sass/assets/fonts', 'public/css/fonts')   

});

The fonts folder is copied under public/css/fonts but yet no icon shows up. What am I missing here? Any clue?

in my app.css the path seems correct, for example:

src: url("fonts/bootstrap/glyphicons-halflings-regular.eot");
Fare answered 14/1, 2016 at 17:23 Comment(1)
Are there any errors showing up, when you call the <code>gulp</code> command in the terminal?Boyette
G
24

I had the same problem with fresh install of laravel 5.2. What I did is just inspected the request path in browser which was :

../build/fonts/bootstrap/glyphicons-halflings-regular.woff2

so I just added to gulp.js this :

mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/','public/build/fonts/bootstrap'); 

and afterwards in terminal :

gulp

That did the trick for me!

Goldstein answered 18/2, 2016 at 2:33 Comment(4)
worked for me by removing build from the target pathUnavailing
Didn't work for me. Using Laravel 5.3 and modified gulpfile.jsEschalot
@BasilMusa Laravel 5.3 remove build dirDorsad
mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/', 'public/fonts/bootstrap'); @BasilMusaDorsad
F
8

You should in your app.scss before including bootstrap file set variable $icon-font-path value correctly, probably in your case it should be:

$icon-font-path: '/css/fonts/';
Fiann answered 14/1, 2016 at 17:42 Comment(4)
@Fare So where your font actually are In public/css/fonts or in public/css/fonts/bootstrap? If in the second one try changing if with valid path.Hyonhyoscine
Second one, bootstrapFare
So try with $icon-font-path: '/css/fonts/bootstrap/'; at the same beginning of your app.scss` fileHyonhyoscine
error was here: I was trying with <span class="glyphicons glyphicons-ok"></span> instead of <span class="glyphicon glyphicon-ok"></span>Fare
E
7

This is what worked for me in Laravel 5.3 on Windows

  1. First make sure you are using the NodeJS package latest version (v6.7.0)

    Click the tab "Current Latest Features" at the URL https://nodejs.org/en/download/current/

  2. Run npm install

  3. Modify the file gulpfile.js to contain the following:

    elixir(mix => {
        mix.sass('app.scss')
           .webpack('app.js');
        mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/','public/fonts/bootstrap');
    });
    
  4. Run gulp:

    gulp
    
  5. Thats it.

Eschalot answered 4/10, 2016 at 10:40 Comment(0)
M
4

In Laravel 5.4, just install npm dependencies and run npm in production or dev as needed.

npm install
npm run production

Laravel will do the rest.

Mortarboard answered 12/7, 2017 at 15:22 Comment(0)
I
3

In Laravel 5.4 what I did is

mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/', 'public/fonts/bootstrap');

And in resources/assets/sass/_variables.scss or app.scss

$icon-font-path: '/fonts/bootstrap/';
Inamorato answered 3/2, 2017 at 4:49 Comment(4)
I use Laravel 5.4, icons doesn't work. I checked my app.css file and saw that font's path is /fonts/. When I manually edit this path to ../fonts instead of /fonts it works. I can not figure out how to make this path. I can't change $icon-font-path' to ../fonts`, it gives me an error.Inexistent
Hi! Make sure your font folder is in public directory and to modify your path it should go like this. $icon-font-path: '/fonts/'; note: you have to edit it on resources/assets/sass/Inamorato
It was in public. I fixed. I changed publicPath in 'webconfig.mix.js' file. Set publicPath for fonts to '../'Inexistent
In a clean install of Laravel 5.4 you simply have to do npm install and npm run dev; the default Laravel setup is already correct.Christianly
D
1

Laravel 5.3 remove build

mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/', 'public/fonts/bootstrap');

run gulp

Dorsad answered 14/10, 2016 at 23:56 Comment(0)
K
1

I had the same problem using Laravel 5.4 It turns out that I hadn't run npm install and npm run dev.

Once these two commands were run, the fonts (and glyphicons) were copied correctly into the /public directory. There was no need to edit any sass or build files.

Klimesh answered 13/5, 2017 at 14:7 Comment(0)
T
1

For Laravel 5.4

This answer didn't exactly solved my problem but it pointed me to the right direction. This is my solution and it covers both if you have defined url for your application (using homestead or some other VM/Vagrant/etc. or if you have set vhost and hosts file for your application), or if you're like me, and have installed lamp stack/xampp/wamp/mapm/etc and doing development from apache htdocs sbfolder.

Firstly you need to add
mix.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/', 'public/fonts/');
in your webpack.mix.js at the end of the file.

Next open up resources/assets/sass/_variable.scss and edit $icon-font-path value.

If you're not using homestead but some lamp stack where you don't have defined dev url for your application (you didn't set vhost and changed hosts file), but instead you're accessing it as a subfolder e.g. localhost/YOUR_APP/public/ then you should set icon font path like
$icon-font-path: "/YOUR_APP/public/fonts/";

If you have set url for your application, you just need to set icon font paht like
$icon-font-path: "/public/fonts/" and recompile css file. You should change to this before pushing your application to the production if it's not set at first!!!

For those who don't know how to recompile css and js files follow this steps:
1. Go to the root of your application and run bash there (git bash, cmd, etc.)
2. npm install
3. npm run-script production (you have other flags available but i perfer production as it minifies js and css)
4. Congrats you just recompiled your js and css

Tanked answered 5/6, 2017 at 10:57 Comment(0)
O
0

If you are using elixir() helper in your blade templates, you should put your fonts files into /public/build. As result /public/build/fonts, the "fonts" folder contains all font files.

Overcloud answered 9/9, 2016 at 11:39 Comment(0)
Z
0
  • Look into developer tools of your browser watch the path.
  • In mine, it was public/fonts/glyphicons-halflings-regular.ttf I downloaded those fonts manually placed them there.
  • And it worked!
Zhao answered 22/12, 2016 at 3:18 Comment(0)
G
0

In webpack.config.js set:

publicPath: '../'

Instead of Mix.resourceRoot

Gadroon answered 31/1, 2018 at 21:48 Comment(0)
D
0

Bootstrap4 doesn't come with icons anymore bootstrap icons

you can use Font Awesome instead for example.

Build your webpack.mix.js configuration.

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

Install Font Awesome.

npm install @fortawesome/fontawesome-free

In /resources/sass/app.scss import one or more styles.

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

now compile.

npm run production
or
npm run dev

Finally, reference your new CSS file in your layout.

<link type="text/css" rel="stylesheet" href="{{ mix('css/app.css') }}">
Date answered 18/6, 2019 at 14:51 Comment(0)
E
-1

Updated answer, I have this implemented now in a much better way, similar to the top answer. In app.scss:

/* BOOTSTRAP */
@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

/* FONT-AWESOME */
$fa-font-path: "../../fonts";
@import "node_modules/font-awesome/scss/font-awesome";
Epiphany answered 14/1, 2016 at 17:37 Comment(1)
@Fare because my CSS file is in build when I mix it with elixir. So when that file references fonts, they are relative to the build folder, not the public folder.Epiphany
A
-1

Try something like:

var gulp = require('gulp');

gulp.task('fonts', function() {
   gulp.src('.node_modules/bootstrap-sass/assets/fonts/bootstrap/fonts/*.{ttf,woff,eof,svg,woff2}')
   .pipe(gulp.dest('public/css/fonts'));
});

and then add

mix
//other scripts
.task('fonts')
Antrim answered 18/1, 2016 at 22:18 Comment(1)
thanks but it was working already, error was here: I was trying with <span class="glyphicons glyphicons-ok"></span> instead of <span class="glyphicon glyphicon-ok"></span>Fare

© 2022 - 2024 — McMap. All rights reserved.