I have a project with Laravel and Vue.js and I use scss. I want to add new font into my project and I can't do this. I create file fonts.scss, create a variable with font
@font-face {
font-family: "Proxima Nova Bold";
src: url(/Proxima-Nova-Bold.otf);
}
$proxima-nova-bold: 'Proxima Nova Bold', sans-serif;
And I have console mistake GET http://local.{my-domain}/Proxima-Nova-Bold.otf net::ERR_ABORTED
Here is how I import scss file in Vue component
@import '../../../fonts/fonts.scss';
Here is my laravel mix
let mix = require('laravel-mix');
mix.copy('resources/assets/images', 'public/images', false)
.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
Where did I make mistake? Or tell me how to add fonts correctly?
To add a Google Font to a Vue. js component, we can imnport it in our CSS. @import url("https://fonts.googleapis.com/css?family=Roboto+Condensed"); Then we can set the font-family to Roboto in the elements we want.
import in main.js inside your vuejs 3 project, /src folder. //vue-app/src/main. js import { library } from "@fortawesome/fontawesome-svg-core"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { fas } from '@fortawesome/free-solid-svg-icons' library.
You can add icons to your Vue 2 or Vue 3 project using a string format or an array format. You can now call the icons, just use the syntax below wherever you want the icons to appear in your project, like in the src/App. vue file.
Start with the font you want, and always end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available. Note: Separate each value with a comma. Note: If a font name contains white-space, it must be quoted.
Works for vue3
<style>
@font-face {
font-family: <name_u_choose>;
src: url('~@/assets/fonts/<static_font_file>.ttf');
}
<style>
<you-selector> {
font-family: <name_u_chose_before>;
}
</style>
Based on this issue in the laravel mix github https://github.com/JeffreyWay/laravel-mix/issues/1172 laravel mix will copy the fonts automatically when referencing them correctly.
Therefore i suggest to use a relative path when referencing the font. This should actually trigger laravel mix to create a folder "fonts" in your "public" folder
@font-face {
font-family: "Proxima Nova Bold";
src: url('./../fonts/Proxima-Nova-Bold.otf');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With