I have a Vue / Vuetify application under development created with the VUE CLI 3.x and would like to serve the Roboto font locally, not via Google cdn.
Has anyone accomplished this via webpack and the vue cli generated vuetify app project and if so how did you go about it?
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.
To change the default font in Vuetify, we can set the font-family CSS property in the global styles. to set the font-family value to $font-family , which is set to 'Ubuntu' . Now our Vuetify app will use Ubuntu as the default font.
With Vue CLI 3 + Vuetify:
install typeface-roboto
npm install --save typeface-roboto
in public/index.html
, remove
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
in src/App.vue
, add
<style lang="sass">
@import '../node_modules/typeface-roboto/index.css'
</style>
First install package typeface-roboto
into your project.
Then import it into your main.js/index.js/boot.js or whatever:
import 'typeface-roboto/index.css';
Finally, update your webpack.config.js
to allow the use of the font file types within the module rules i.e.:
module: {
rules: [
//other stuff
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, use: 'url-loader?limit=25000' }
]
},
The font file types are woff
, woff2
, eot
and ttf
.
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