Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

purifycss-webpack

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purifycss-webpack

PurifyCSS for webpack

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
decreased by-12.41%
Maintainers
1
Weekly downloads
 
Created
Source

build status bitHound Score codecov

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!

Usage

First, install it:

npm install purifycss-webpack --save-dev

Then configure as follows:

const path = require('path');
const glob = require('glob');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PurifyPlugin = 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 PurifyPlugin({
      // 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".

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:

PropertyDescription
fileExtensionsAn array of file extensions for determining used classes. Defaults to ['.css'].
moduleExtensionsAn array of file extensions for determining used classes within node_modules. Defaults to [], but ['.html'] can be useful here.
pathsAn 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.
purifyOptionsPass custom options to PurifyCSS.
verboseSet 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!

License

ISC.

Keywords

FAQs

Package last updated on 24 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc