1

I am trying to build an app using Nuxt, Firebase and Vuetify. I am a novice developer and will appreciate kind help on the below issue.

I can not add Google Fonts (lastly tried Bellefair)or change global default font-size to my Nuxt with Vuetify project. My nuxt.config.js is below. Also I cannot change the default font size. I have tried various snippets I have found around but none seemed to work so far. I have lastly reached the below, but still to no success.


import colors from "vuetify/es5/util/colors";

export default {
  mode: "spa",

  head: {
    titleTemplate: "%s - " + process.env.npm_package_name,
    title: process.env.npm_package_name || "",
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      {
        hid: "description",
        name: "description",
        content: process.env.npm_package_description || ""
      }
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }, {
      rel: "stylesheet", href:"https://fonts.googleapis.com/css?family=Bangers|Bellefair"
    }]
  },

  loading: "@/components/loading",

  css: [],

  plugins: ["@/plugins/fireauth.js"],

  buildModules: ["@nuxtjs/vuetify"],

  modules: [
    "@nuxtjs/axios",
    "@nuxtjs/pwa",
    "@nuxtjs/date-fns"
  ],
  router: {
    middleware: "fb-auth"
  },

  axios: {},

  vuetify: {
    customVariables: ["~assets/styles/variables.scss"],
    theme: {
      light: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3
        }
      }
    }
  },
  /*
   ** Build configuration
   */
  build: {
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {}
  }
};

and my ~assets/styles/variables.scss file is:


$body-font-family: "Bellefair", sans-serif;
$font-size-root: 20px;

@font-face {
  font-family: "Bellefair";
  src: url("https://fonts.googleapis.com/css?family=Bellefair");
}

body {
    font-family: "Bellefair", sans-serif;
}

EDITED: //\//\//\//\//\//\ I found a solution to my own question:

I added= css: ['~/assets/styles/my-custom-styles.css'] to my nuxt.config.js and in that file

div {
   font-family: "Montserrat", sans-serif;
   font-size: 18px;
}

Also, I realized that my nuxt.config.js header does not need the stylesheet link to googleapis.com.

Sorry about taking space here but am always welcome to see better responses...

Cenan
  • 11
  • 3
  • Answered here https://stackoverflow.com/questions/51436344/how-to-embed-font-to-all-page-with-nuxt-js/60782370#60782370 – Anees Hameed Mar 29 '20 at 18:16

1 Answers1

0

1. Add your google font embed the link in nuxt.config.js, for example, to add DM Sans font.

head: {
  titleTemplate: '%s - ' + process.env.npm_package_name,
    title: process.env.npm_package_name || '',
      meta: [
        { charset: 'utf-8' },
        { name: 'viewport', content: 'width=device-width, initial-scale=1' },
        { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
      ],
        link: [
          { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
          {
            rel: 'stylesheet', href: '<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&display=swap" rel="stylesheet"> '
          }
        ] },

2. enable treeshaking in vuetify section on nuxt.config.js .

vuetify: {
  customVariables: ['~/assets/variables.scss'],
  treeShake: true,
}

3. Add the rule assets/variable.scss:

$body-font-family : 'DM Sans', sans-serif;
Azametzin
  • 5,223
  • 12
  • 28
  • 46
Yoga Altariz
  • 32
  • 1
  • 3