Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract CSS in NUXTjs generate

When using nuxt generate I am generating various HTML pages that happen to be about 300 kB in size. Majority of the file is CSS style placed inline to it. Is it a way to put it in an external file and reduce size of HTML ?

like image 449
bensiu Avatar asked Jun 19 '18 01:06

bensiu


People also ask

Does NUXT use PostCSS?

Note: Nuxt has applied PostCSS Preset Env . By default it enables Stage 2 features and Autoprefixer , you can use build. postcss.

Does NUXT 3 Use webpack?

Nuxt 3 will support bundling with both the latest version of Webpack (version 5) as well as Vite for both development and production builds. Whichever one you choose, you'll be sure to experience a faster development experience and decreased production build times.

Does NUXT use Babel?

Usage. Nuxt allows to customize the babel configuration for the build. But this does not take module files or nuxt. config.


1 Answers

You can extract the CSS in the main chunk into a separate CSS file using

nuxt.config.js

module.exports = {
  build: {
    extractCSS: true
  }
}

This is documented here

If you want to import css files globally use

module.exports = {
  css: [
    // Load a Node.js module directly (here it's a Sass file)
    'bulma',
    // CSS file in the project
    '@/assets/css/main.css',
    // SCSS file in the project
    '@/assets/css/main.scss'
  ]
}

as documented here

like image 113
HexXx Avatar answered Oct 13 '22 01:10

HexXx