$ cnpm install nuxt-purgecss
nuxt-purgecss
dependency to your projectyarn add --dev nuxt-purgecss # or npm install --save-dev nuxt-purgecss
nuxt-purgecss
to the buildModules
section of nuxt.config.js
export default {
buildModules: [
// Simple usage
'nuxt-purgecss',
// With options
['nuxt-purgecss', { /* module options */ }]
]
}
:warning: If you are using Nuxt < v2.9 you have to install the module as a dependency
(No --dev
or --save-dev
flags) and use modules
section in nuxt.config.js
instead of buildModules
.
Before diving into the individual attributes, please have a look at the default settings of the module.
The defaults will scan all your .vue
or .js
components in the common Nuxt folders, as well as checking your nuxt.config.js
for used classes. Furthermore, typical classes (like these needed for transitions, the nuxt link ones or those set when using scoped styles) are whitelisted already.
These settings should be a good foundation for a variety of projects.
You can define every option either as function or as static value (primitives, objects, arrays, ...). if you use a function, the default value will be provided as the first argument.
If you don't use a function to define you properties, the module will try to merge them with the default values. This can be handy for paths
, whitelist
and so on because the defaults are quite sensible. If you don't want to have the defaults include, just use a function.
String
('webpack' or 'postcss')postcss
Defines the mode, PurgeCSS should be used in.
build.extractCSS: true
build.postcss
object (no array) or default settingsBoolean
options.dev === false
(Disabled during nuxt dev
, enabled otherwise)Enables/Disables the module
Please read the PurgeCSS docs for information about PurgeCSS-related information.
Instead of content
we use paths
to specify the paths PurgeCSS should look into (explained here. This applies to both modes, not only to webpack mode
.
//nuxt.config.js
export default {
modules: [
'nuxt-purgecss',
]
}
//nuxt.config.js
export default {
modules: [
'nuxt-purgecss',
],
purgeCSS: {
whitelist: () => ['only-this-class']
}
}
//nuxt.config.js
export default {
modules: [
'nuxt-purgecss',
],
purgeCSS: {
whitelist: ['defaults-and-this-class']
}
}
//nuxt.config.js
export default {
modules: [
'nuxt-purgecss',
],
purgeCSS: {
whitelist: (defaultWhitelst) => defaultWhitelst.slice(1)
}
}
Only one extractor can be applied to each file extention. If you want to apply a custom extractor to the extensions that the default extractor already covers, you have to override the default extractor. This is only possible with the functional notation.
//nuxt.config.js
export default {
modules: [
'nuxt-purgecss',
],
purgeCSS: {
extractors: () => [
{
extractor(content) {
return content.match(/[A-z0-9-:\\/]+/g)
},
extensions: ['html', 'vue', 'js']
},
{
extractor(content) {
return content.match(/[A-z0-9-\\/]+/g)
},
extensions: ['vue'] // This will not work, because the above extractor is applied to 'vue' already.
}
]
}
}
mode: 'webpack'
to your config.postcss
mode, you can remove the mode: 'postcss'
line from your configtailwind
module, you don't need to do anythingnuxt-link-active
). If you whitelisted these before, you can remove them.Copyright (c) Alexander Lichter
Copyright 2014 - 2017 © taobao.org |