0

The problem I am facing is when I run the project using npm run dev, the fonts are loaded exactly how I want

enter image description here

but when I make a build and run the command npm run start, the fonts are different

enter image description here

This is how my nuxt.config file looks like

var dynamicPages = require('./dynamicPages.json')

export default {
  // Target: https://go.nuxtjs.dev/config-target
  target: 'server',
  buildDir: '_nuxt/dist/',
  // build: {
  //   publicPath: '_nuxt/dist/'
  // },

  generate: { routes: dynamicPages },

  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'level-1',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    '~/assets/styles/style.scss',
    '~/assets/fonts.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    { src: '~/plugins/analytics.js', mode: 'client' }
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    '@nuxtjs/google-analytics'
  ],

  apollo: {
    clientConfigs: {
      default: {
        httpEndpoint: "https://rickandmortyapi.com/graphql"
      }
    }
  },

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/bootstrap
    'bootstrap-vue/nuxt',
    'nuxt-helmet',
    '@nuxtjs/apollo',
    'nuxt-helmet',
    'nuxt-webfontloader',
    '@nuxtjs/gtm',
    'nuxt-fontawesome',
  ],

  router: {
    // trailingSlash: false,
    middleware: 'trailingSlashRedirect',
  },

  fontawesome: {
    imports: [
        {
          set: '@fortawesome/free-solid-svg-icons',
          icons: ['fas']
        },
        {
          set:'@fortawesome/free-brands-svg-icons',
          icons: ['fab']
        }
    ],
  },


  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {

    // extend (config, ctx) {
    //   // Run ESLint on save
    //   if (ctx.isDev && ctx.isClient) {
    //     config.module.rules.push({
    //       enforce: 'pre',
    //       test: /\.(js|vue)$/,
    //       loader: 'eslint-loader',
    //       exclude: /(node_modules)/
    //     })
    //   }
    // }
  },
}

is there an issue with how my nuxt file looks like? any suggestions?

  • Hi, no idea with just a screenshot. Could you please share your `nuxt.config.js` file or anything relevant to debug this one? – kissu Dec 08 '21 at 10:30
  • Also, look into your network tab, it may give you some hints as of why it's not being loaded. You do have `target: 'server'` or `'static'` in your `nuxt.config.js` file? – kissu Dec 08 '21 at 10:31
  • What if you comment `buildDir`? This is probably breaking the relative path to your fonts. – kissu Dec 08 '21 at 10:38
  • Also, what about your actual configuration of the fonts? – kissu Dec 08 '21 at 10:39
  • no luck with the comment of buildDir. also what do you mean by font configuration. I added the fonts on the css array on the nuxt file as shown. thankyou – Essam Tariq Dec 08 '21 at 10:53
  • What exactly is in this `fonts.css`? Usually, you do have a `src/assets/fonts/` directory with `my-cool-font.ttf` inside of it. And then, you reference the actual font with something like `src: url('../fonts/my-cool-font.ttf') format('truetype'),` inside of it. [This website](https://google-webfonts-helper.herokuapp.com/fonts/inter?subsets=latin) can be pretty handy. Otherwise, if you want to have a module fetching the latest fonts, you can refer to my [answer here](https://stackoverflow.com/a/68166329/8816585). Otherwise, I don't know any other approach to load fonts efficiently. – kissu Dec 08 '21 at 11:11
  • I found the Answer. The problem was similar to this https://stackoverflow.com/questions/66228973/nuxt-generate-font-does-not-apply – Essam Tariq Dec 08 '21 at 14:30
  • Not sure that this is a valid solution, but you do you. – kissu Dec 08 '21 at 15:56

0 Answers0