PurifyCSS for webpack
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!
First, install it:
npm install purifycss-webpack --save-dev
Then configure as follows:
const path = ;const glob = ;const ExtractTextPlugin = ;const PurifyCSSPlugin = ;moduleexports =entry: ...output: ...module:rules:test: /\.css$/loader: ExtractTextPluginplugins:'[name].[contenthash].css'// Make sure this is after ExtractTextPlugin!// Give paths to parse for rules. These should be absolute!paths: glob;
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
pathsif you want to control the behavior per entry.
This plugin, unlike the original PurifyCSS plugin, provides special features, such as scanning the dependency files. You can configure using the following fields:
||An array of file extensions for determining used classes within style files. Defaults to
||An array of file extensions for determining used classes within
||Enable CSS minification. Alias to
||An array of absolute paths or a path to traverse. This also accepts an object (
||Pass custom options to PurifyCSS.|
||Set this flag to get verbose output from the plugin. This sets
The plugin does not emit sourcemaps even if you enable
sourceMapoption on loaders!