purifycss-webpack

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

Github星跟踪图

UNMAINTAINED

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


npm
deps
test
coverage
quality
chat

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!

npm i -D purifycss-webpack purify-css

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.

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!

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*']
      }
    })
  ]
};

主要指标

概览
名称与所有者webpack-contrib/purifycss-webpack
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-05-19 17:05:01
推送于2018-12-25 14:59:09
最后一次提交2018-12-25 17:59:08
发布数17
最新版本名称v0.7.0 (发布于 2017-05-16 17:45:36)
第一版名称old-v2.0.3 (发布于 )
用户参与
星数768
关注者数23
派生数36
提交数206
已启用问题?
问题数111
打开的问题数40
拉请求数26
打开的拉请求数5
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?