All Projects → webpack-contrib → Purifycss Webpack

webpack-contrib / Purifycss Webpack

Licence: mit
UNMAINTAINED, use https://github.com/FullHuman/purgecss-webpack-plugin

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Purifycss Webpack

Web Webpack Plugin
alternative for html-webpack-plugin
Stars: ✭ 318 (-59.7%)
Mutual labels:  webpack-plugin
Extract Text Webpack Plugin
[DEPRECATED] Please use https://github.com/webpack-contrib/mini-css-extract-plugin Extracts text from a bundle into a separate file
Stars: ✭ 4,071 (+415.97%)
Mutual labels:  webpack-plugin
Optimize Plugin
Optimized Webpack Bundling for Everyone. Intro ⤵️
Stars: ✭ 525 (-33.46%)
Mutual labels:  webpack-plugin
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (-55.39%)
Mutual labels:  webpack-plugin
Webpack Chrome Extension Reloader
🔥 Hot reloading while developing Chrome extensions with webpack 🔥
Stars: ✭ 365 (-53.74%)
Mutual labels:  webpack-plugin
Webpack Parallel Uglify Plugin
A faster uglifyjs plugin.
Stars: ✭ 456 (-42.21%)
Mutual labels:  webpack-plugin
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (-61.22%)
Mutual labels:  webpack-plugin
Duplicate Package Checker Webpack Plugin
🕵️ Webpack plugin that warns you when a build contains multiple versions of the same package
Stars: ✭ 635 (-19.52%)
Mutual labels:  webpack-plugin
Moment Locales Webpack Plugin
Easily remove unused Moment.js locales with webpack
Stars: ✭ 396 (-49.81%)
Mutual labels:  webpack-plugin
Babel Minify Webpack Plugin
[DEPRECATED] Babel Minify Webpack Plugin
Stars: ✭ 502 (-36.38%)
Mutual labels:  webpack-plugin
Webpack Extension Reloader
A upgrade from 🔥webpack-chrome-extension-reloader🔥, now on all browsers
Stars: ✭ 355 (-55.01%)
Mutual labels:  webpack-plugin
Browser Sync Webpack Plugin
Easily use BrowserSync in your Webpack project.
Stars: ✭ 356 (-54.88%)
Mutual labels:  webpack-plugin
Webpack Spritesmith
Webpack plugin that converts set of images into a spritesheet and SASS/LESS/Stylus mixins
Stars: ✭ 468 (-40.68%)
Mutual labels:  webpack-plugin
I18n Webpack Plugin
[DEPRECATED] Embed localization into your bundle
Stars: ✭ 320 (-59.44%)
Mutual labels:  webpack-plugin
Webpack Config Plugins
Provide best practices for webpack loader configurations
Stars: ✭ 529 (-32.95%)
Mutual labels:  webpack-plugin
Filemanager Webpack Plugin
Copy, move, archive (zip/tar/tar.gz), delete files and directories before and after Webpack builds. Win32/Mac/*Nix supported
Stars: ✭ 310 (-60.71%)
Mutual labels:  webpack-plugin
Mini Css Extract Plugin
Lightweight CSS extraction plugin
Stars: ✭ 4,396 (+457.16%)
Mutual labels:  webpack-plugin
Purgecss
Remove unused CSS
Stars: ✭ 6,566 (+732.19%)
Mutual labels:  webpack-plugin
Webpack Deep Scope Analysis Plugin
A webpack plugin for deep scope analysis
Stars: ✭ 589 (-25.35%)
Mutual labels:  webpack-plugin
Offline Plugin
Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
Stars: ✭ 4,444 (+463.24%)
Mutual labels:  webpack-plugin

UNMAINTAINED

Please use: https://github.com/FullHuman/purgecss-webpack-plugin


npm deps test coverage quality chat

PurifyCSS Plugin

PurifyCSS for Webpack.

This plugin uses PurifyCSS to remove unused selectors from your CSS. You should use it with the extract-text-webpack-plugin.

Without any CSS file being emitted as an asset, this plugin will do nothing. You can also use the file plugin to drop a CSS file into your output folder, but it is highly recommended to use the PurifyCSS plugin with the Extract Text plugin.

This plugin replaces earlier purifycss-webpack-plugin and it has a different API!

Install

npm i -D purifycss-webpack purify-css

Usage

Configure as follows:

const path = require('path');
const glob = require('glob');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PurifyCSSPlugin = require('purifycss-webpack');

module.exports = {
  entry: {...},
  output: {...},
  module: {
    rules: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: 'css-loader'
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('[name].[contenthash].css'),
    // Make sure this is after ExtractTextPlugin!
    new PurifyCSSPlugin({
      // Give paths to parse for rules. These should be absolute!
      paths: glob.sync(path.join(__dirname, 'app/*.html')),
    })
  ]
};

And, that's it! Your scripts and view files will be scanned for classes, and those that are unused will be stripped off your CSS - aka. "purified".

In order to use this plugin to look into multiple paths you will need to:

  1. npm install --save glob-all
  2. Add const glob = require('glob-all'); at the top of your webpack config
  3. Then you can pass your paths to an array, like so:
paths: glob.sync([
  path.join(__dirname, '.php'),
  path.join(__dirname, 'partials/.php')
]),

You can pass an object (<entry> -> [<absolute path>]) to paths if you want to control the behavior per entry.

Options

This plugin, unlike the original PurifyCSS plugin, provides special features, such as scanning the dependency files. You can configure using the following fields:

Property Description
styleExtensions An array of file extensions for determining used classes within style files. Defaults to ['.css'].
moduleExtensions An array of file extensions for determining used classes within node_modules. Defaults to [], but ['.html'] can be useful here.
minimize Enable CSS minification. Alias to purifyOptions.minify. Disabled by default.
paths An array of absolute paths or a path to traverse. This also accepts an object (<entry name> -> <paths>). It can be a good idea glob these.
purifyOptions Pass custom options to PurifyCSS.
verbose Set this flag to get verbose output from the plugin. This sets purifyOptions.info, but you can override info separately if you want less logging.

The plugin does not emit sourcemaps even if you enable sourceMap option on loaders!

Usage with CSS Modules

PurifyCSS doesn't support classes that have been namespaced with CSS Modules. However, by adding a static string to css-loader's localIdentName, you can effectively whitelist these namespaced classes.

In this example, purify will be our whitelisted string. Note: Make sure this string doesn't occur in any of your other CSS class names. Keep in mind that whatever you choose will end up in your application at runtime - try to keep it short!

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                localIdentName: 'purify_[hash:base64:5]',
                modules: true
              }
            }
          ]
        })
      }
    ]
  },
  plugins: [
    ...,
    new PurifyCSSPlugin({
      purifyOptions: {
        whitelist: ['*purify*']
      }
    })
  ]
};

Maintainers

Juho Vepsäläinen Joshua Wiens Kees Kluskens Sean Larkin
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].