How to load a font file in vuejs and webpack?
Hope this will help others who are facing the same issue. For some reason Vue.js is giving error when using .otf
files. I used .woff
and now everything works fine. Use the following code in your webpack.config.js
file :
module.exports = function (config, { isClient, isDev }) {
module: { rules: [ { test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/,
loader: 'file-loader' } ] }
return config }
and import the files in your css file using something like this
@font-face {
font-family: "Questrial";
src: url("../../fonts/Questrial-Regular.ttf");
}
Can't load font with webpack & vuejs
Okay I finaly found a way to use my customs fonts :
I had the correct syntax but I just had to use .woff or .woff2 font files instead of .ttf or .otf. I can't explain why it's not working anymore, but I got what I wanted so it's allright ~
Vue Cli 3 Local fonts not loading
Did you try
@font-face {
font-family: 'OpenSans-Regular';
src: url('~@/assets/fonts/OpenSans-Regular.eot');
src: url('~@/assets/fonts/OpenSans-Regular.eot?#iefix') format('embedded-opentype'),
url('~@/assets/fonts/OpenSans-Regular.otf') format('font-opentype'),
url('~@/assets/fonts/OpenSans-Regular.woff') format('font-woff'),
url('~@/assets/fonts/OpenSans-Regular.ttf') format('font-truetype'),
url('~@/assets/fonts/OpenSans-Regular.svg#OpenSans-Regular') format('svg');
font-weight: normal;
font-style: normal;
}
Works for me Vue CLI 3, no vue.config.js
settings.
I'm loading my styles like this:
import Vue from 'vue';
import router from './router';
import store from './store';
// eslint-disable-next-line
import styles from './scss/app.scss';
import App from './App.vue';
Vue.config.productionTip = false;
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app');
Not sure if that is good practice.
Cannot embed custom fonts using vuejs2 and webpack
Sorry this is solved it required ../src
Related Topics
Focus Next Input Once Reaching Maxlength Value
Reactjs How to Call a Component Function from Another Function on the Same File
Prevent User from Typing in Input At Max Value
Node Server Running But Localhost Refusing to Connect
React-Select:Get Default Value in React-Select
How to Access a Model Attribute With JavaScript Variable
How to Place Button on Right Side in Reactjs
Javascript to Hide Multiple Div
How to Highlight a Part of Text in Textarea
Js Li Tag Onclick Not Working on Ie8
Does Jest Swallow Console.Log Statements How to Change This
Disabled Button Onclick Event Fires
How to Remember the Value of a Variable After Reloading the Page
How to Append Whole Set of Model to Formdata and Obtain It in MVC
Disable Scrolling When Touch Moving Certain Element
I Want to Change the Page Background Color, But It Doesn't Work as I Expect in Chrome
Setting Iframe Height to Scrollheight in Reactjs
How to Listen to the Window Scroll Event in a Vuejs Component