Nuxt
Module
There is a community module called nuxt-purgecss to make the usage of PurgeCSS with Nuxt as easy as possible. With it's fitting defaults, you only need to make a few changes (or none at all) to the configuration.
Example
You can see an example using the nuxt-purgecss
module in our examples directory.
Manual configuration
Example
You can see an example here.
create-nuxt-app and webpack plugin
This example shows how to set up PurgeCSS with create-nuxt-app
Once you initialized your project with
and selected the options that fit your needs, install the webpack plugin for PurgeCSS together with glob-all
:
You need to modify the file nuxt.config.js
by adding he following code:
line 1
In your build
segment
In your build.extend
function.
Results
This example is importing the tachyons css framework. Without PurgeCSS, the base css file size is 88.2 kB. Using PurgeCSS, the base css file is 1.56 kB
PostCSS plugin
Using the extractCSS option Nuxt will create CSS files that will be loaded separately by the browser. When generating your application this might be a lot of small files.
To include the CSS into the header of the HTML file you'll need to run the following commands. Please note that using this configuration PurgeCSS will be active in production and development mode.
Last updated