Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output css files as .css files instead of inline <style> in nuxt.js?

How can I convert inline-CSS to CSS-files in nuxt.js? I have both scoped styles and global scss file in my app. I have already tried below code but no luck.

build: {
    optimization: {
      splitChunks: {
        chunks: 'all',
        automaticNameDelimiter: '.',
        name: 'rameez',
        cacheGroups: {}
      }
    },
    optimizeCSS:true
  }

here you can see all the CSS including my global.scss is shown as an inline style.

enter image description here

like image 250
Rameez Rami Avatar asked Mar 05 '19 07:03

Rameez Rami


People also ask

Where do I put CSS files in NUXT?

Now about you doubt if you want to import the CSS as globally, the correct place is inside your nuxt. config. js, inside this file, you have a property called head, and inside the head we will configure all the imports. So, inside nuxt.

How do you inline a CSS file?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

How do I give a div inline style?

Inline Style Syntax The style attribute is just like any other HTML attribute. It goes inside the element's beginning tag, right after the tag name. The attribute starts with style , followed by an equals sign, = , and then finally uses double quotes, "" , which contain the value of the attribute.

Does inline style affect performance?

Ultimately, it's important in terms of inlining CSS and performance that you don't just dump all the CSS for your site into the head. If you inline too much, the performance implications will be worse than what you started with.


1 Answers

You are looking for extractCss property i think

build:{
    extractCSS: true
}
like image 110
Aldarund Avatar answered Oct 20 '22 04:10

Aldarund