Nuxt.js: Not rendering CSS in code

Created on 19 Sep 2017  路  14Comments  路  Source: nuxt/nuxt.js

I want to just use .css file in image
How can I do this?

This question is available on Nuxt.js community (#c1513)
help-wanted

Most helpful comment

Put it in your nuxt.config.js

/* nuxt.config.js */
module.exports = {
  head: {
    titleTemplate: '%s - Nuxt.js',
    meta: [
      link: { rel: 'stylesheet', href: '/css/index.css' }
    ]
  }
}

All 14 comments

since nuxt uses vue-meta you can use the head() method and in there use the link property.

export default {
  head () {
    return {
      metaInfo: {
        link: { rel: 'stylesheet', href: '/css/index.css' }
      }
    }
  }
}

how about applying in all webpage instead of each pages

Put it in your nuxt.config.js

/* nuxt.config.js */
module.exports = {
  head: {
    titleTemplate: '%s - Nuxt.js',
    meta: [
      link: { rel: 'stylesheet', href: '/css/index.css' }
    ]
  }
}

link: { rel: 'stylesheet', href: '/assets/index.css' }
I got 404 when access http://localhost:3000/assets/rocket.css. How define path, pro?

you reference an index.css but want to get rocket.css...

@vuchl Sorry I made a mistake, I would to say getting 404 when access http://localhost:3000/assets/index.css

try metaInfo instead of meta

@vuchl Got error too :(

Ok. Put the index.css file in the assets folder and in the nuxt.config.js setup the following:

module.exports {
  head: {
    link: [
      { rel: 'stylesheet', href: '/index.css' }
    ]
  }
}

it would also work to put it in the static folder

@vuchl If I put file index.css into folder static. It is success but I want to put file .css in folder assets. Your way is failed. I think need to define Folder Path.

You are right. seems like I had a duplicate or something. If you want it in the app globally you can also set it in your nuxt.config.js in the css property: https://nuxtjs.org/api/configuration-css

So for you: remove the link in nuxt.config,jss head and add it to the css property like

module.exports {
  css: {
    '@/assets/index.css'
  }
}

@vuchl If do this, CSS will be rendered as normal.
I think need to define Folder Assests Path like folder static.

You should use the static folder in this case.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pehbehbeh picture pehbehbeh  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

gary149 picture gary149  路  3Comments

jaredreich picture jaredreich  路  3Comments

vadimsg picture vadimsg  路  3Comments