Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue cli and vuetify how to use with local Roboto font

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?

like image 549
JohnC Avatar asked Nov 23 '18 20:11

JohnC


People also ask

How do I import Google fonts into Vue?

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.

How do I change Vuetify default font?

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.


2 Answers

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>
    
like image 148
Sylvain Lesage Avatar answered Oct 27 '22 08:10

Sylvain Lesage


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.

like image 39
soupjake Avatar answered Oct 27 '22 09:10

soupjake