All Projects → Developmint → Nuxt Purgecss

Developmint / Nuxt Purgecss

Licence: mit
Drop superfluous CSS! A neat PurgeCSS wrapper for Nuxt.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Nuxt Purgecss

Lichter.io
My own website and CV
Stars: ✭ 105 (-70.51%)
Mutual labels:  webpack, nuxt, nuxtjs
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (-70.51%)
Mutual labels:  webpack, nuxt, nuxtjs
Nuxt Ssr Firebase
Nuxt.js Universal App with SSR via Firebase Functions and Firebase Hosting
Stars: ✭ 273 (-23.31%)
Mutual labels:  nuxt, nuxtjs
Nuxt7
📱 Full Featured iOS & Android PWA Apps with Nuxt.js and Framework7
Stars: ✭ 282 (-20.79%)
Mutual labels:  nuxt, nuxtjs
Blog Front
blog-front @nuxt
Stars: ✭ 305 (-14.33%)
Mutual labels:  nuxt, nuxtjs
Shopify Theme Lab
Shopify theme development environment using Liquid, Vue and Tailwind CSS 🧪
Stars: ✭ 250 (-29.78%)
Mutual labels:  webpack, postcss
Nuxt Webfontloader
Efficient web font loading has never been easier!
Stars: ✭ 264 (-25.84%)
Mutual labels:  nuxt, nuxtjs
Graphcms Examples
Example projects to help you get started with GraphCMS
Stars: ✭ 295 (-17.13%)
Mutual labels:  nuxt, nuxtjs
nuxt wp
Repo for my blog series on a building a site with WordPress REST API, Vue, and Nuxt.js
Stars: ✭ 41 (-88.48%)
Mutual labels:  nuxt, nuxtjs
Kratos Boilerplate
🔥 A simple boilerplate for creating statics PWA using Webpack, Pug, PostCSS and CSS Modules
Stars: ✭ 308 (-13.48%)
Mutual labels:  webpack, postcss
React Redux Boilerplate
Awesome React Redux Workflow Boilerplate with Webpack 4
Stars: ✭ 307 (-13.76%)
Mutual labels:  webpack, postcss
Pwa
An opinionated progressive web app boilerplate
Stars: ✭ 353 (-0.84%)
Mutual labels:  webpack, postcss
nuxt-star-admin-extra
Admin Template base on Vue StarAdmin with improved on design and served using Nuxt.js
Stars: ✭ 19 (-94.66%)
Mutual labels:  nuxt, nuxtjs
admin-null-nuxt
Admin Null — Free Nuxt Bulma Admin Dashboard (with dark mode)
Stars: ✭ 39 (-89.04%)
Mutual labels:  nuxt, nuxtjs
Frontend Boilerplates
Collection of Boilerplates with ES6, Vue, React, Nuxt, TypeScript, SCSS, Nodejs. Using good practices and file structures to inspire your real projects.
Stars: ✭ 269 (-24.44%)
Mutual labels:  webpack, nuxt
test-utils
Test utilities for Nuxt.js
Stars: ✭ 100 (-71.91%)
Mutual labels:  nuxt, nuxtjs
Webpack Blocks
📦 Configure webpack using functional feature blocks.
Stars: ✭ 2,992 (+740.45%)
Mutual labels:  webpack, postcss
Electron React Webpack Boilerplate
Minimal Electron, React, PostCSS and Webpack boilerplate to help you get started with building your next app.
Stars: ✭ 312 (-12.36%)
Mutual labels:  webpack, postcss
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (-88.48%)
Mutual labels:  nuxt, nuxtjs
nuxt-blog
📝 Personal blog built with Nuxt.js and wordpress rest api
Stars: ✭ 13 (-96.35%)
Mutual labels:  nuxt, nuxtjs

Nuxt PurgeCSS - Drop superfluous CSS!

npm version npm downloads Github Actions CI Codecov License thanks

📖 Release Notes

Features

  • Remove unneeded CSS with ease
  • Webpack or PostCSS mode
  • Already comes with mighty default settings
  • Built on top of purgecss
  • Nuxt 2 (and only Nuxt 2) support
  • Fully tested!

Setup

  1. Add nuxt-purgecss dependency to your project
yarn add --dev nuxt-purgecss # or npm install --save-dev nuxt-purgecss
  1. Add nuxt-purgecss to the buildModules section of nuxt.config.js
export default {
  buildModules: [
    // Simple usage
    'nuxt-purgecss',

    // With options
    ['nuxt-purgecss', { /* module options */ }],
  ]
}

⚠️ 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.

Options

Defaults

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.

Merging defaults

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.

Properties in-depth

mode

  • Type: String ('webpack' or 'postcss')
  • Default: postcss

Defines the mode, PurgeCSS should be used in.

  • Webpack mode can only be used with build.extractCSS: true
  • PostCSS mode can only be used with a build.postcss object (no array) or default settings

enabled

  • Type: Boolean
  • Default: options.dev === false (Disabled during nuxt dev, enabled otherwise)

Enables/Disables the module

PurgeCSS options

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.

Examples

Default setup

//nuxt.config.js
export default {
  buildModules: [
    'nuxt-purgecss',
  ]
}

Override a default value

//nuxt.config.js
export default {
  buildModules: [
    'nuxt-purgecss',
  ],

  purgeCSS: {
   whitelist: () => ['only-this-class'],
  }
}

Append a value to the defaults

//nuxt.config.js
export default {
  buildModules: [
    'nuxt-purgecss',
  ],

  purgeCSS: {
   whitelist: ['defaults-and-this-class'],
  }
}

Override a default value

//nuxt.config.js
export default {
  buildModules: [
    'nuxt-purgecss',
  ],

  purgeCSS: {
   whitelist: (defaultWhitelst) => defaultWhitelst.slice(1),
  }
}

Use custom extractors

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 {
  buildModules: [
    '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.
      }
    ]
  }
}

Migrating from v0.x

  1. Review the Release Notes for all changes
  2. Bump to 1.x
  3. Ensure the plugin is running in the right mode
    • If you used the default mode, you have to add mode: 'webpack' to your config.
    • If you used the postcss mode, you can remove the mode: 'postcss' line from your config
    • If you used this module only with the Nuxt tailwind module, you don't need to do anything
  4. Read about the internal changes of PurgeCSS 2
  5. Update your extractor and change the syntax from a class to a function (see 4.)
  6. Unused styles from SFCs are now purged. If you don't want that, whitelist them.
  7. The regex for CSS classes changed. This should not be breaking in most cases.
  8. The whitelist now includes nuxt link classes (e.g. nuxt-link-active). If you whitelisted these before, you can remove them.
  9. The whitelist now includes move transition classes. If you whitelisted these before, you can remove them.
  10. Test on your staging server (or locally) before deploying!

License

MIT License

Copyright (c) Alexander Lichter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].