lib/index.js
function buildCritical() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  var filteredOptions = Object.keys(options).reduce(function (acc, key) {
    return typeof options[key] !== 'undefined' ? _extends({}, acc, _defineProperty({}, key, options[key])) : acc;
  }, {});
  var args = _extends({
    outputPath: process.cwd(),
    outputDest: 'critical.css',
    preserve: true,
    minify: true,
    dryRun: false
  }, filteredOptions);
  append = false;
  return function (css) {
    var dryRun = args.dryRun,
        preserve = args.preserve,
        minify = args.minify,
        outputPath = args.outputPath,
        outputDest = args.outputDest;

    var criticalOutput = (0, _getCriticalRules.getCriticalRules)(css, outputDest);
    return Object.keys(criticalOutput).reduce(function (init, cur) {
      var criticalCSS = _postcss2.default.root();
      var filePath = _path2.default.join(outputPath, cur);
      criticalOutput[cur].each(function (rule) {
        return criticalCSS.append(rule.clone());
      });
      return (0, _postcss2.default)(minify ? [_cssnano2.default] : [])
      // @TODO Use from/to correctly.
      .process(criticalCSS, {
        from: undefined
      }).then(dryRunOrWriteFile.bind(null, dryRun, filePath)).then(clean.bind(null, css, preserve));
    }, {});
  };
}
function buildCritical() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  var filteredOptions = Object.keys(options).reduce(function (acc, key) {
    return typeof options[key] !== 'undefined' ? _extends({}, acc, _defineProperty({}, key, options[key])) : acc;
  }, {});
  var args = _extends({
    outputPath: process.cwd(),
    outputDest: 'critical.css',
    preserve: true,
    minify: true,
    dryRun: false
  }, filteredOptions);
  append = false;
  return function (css) {
    var dryRun = args.dryRun,
        preserve = args.preserve,
        minify = args.minify,
        outputPath = args.outputPath,
        outputDest = args.outputDest;

    var criticalOutput = (0, _getCriticalRules.getCriticalRules)(css, outputDest);
    return Object.keys(criticalOutput).reduce(function (init, cur) {
      var criticalCSS = _postcss2.default.root();
      var filePath = _path2.default.join(outputPath, cur);
      criticalOutput[cur].each(function (rule) {
        return criticalCSS.append(rule.clone());
      });
      return (0, _postcss2.default)(minify ? [_cssnano2.default] : [])
      // @TODO Use from/to correctly.
      .process(criticalCSS, {
        from: undefined
      }).then(dryRunOrWriteFile.bind(null, dryRun, filePath)).then(clean.bind(null, css, preserve));
    }, {});
  };
}
function buildCritical ( ) { var options = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ; var filteredOptions = Object . keys ( options ) . reduce ( function ( acc , key ) { return typeof options [ key ] !== 'undefined' ? _extends ( { } , acc , _defineProperty ( { } , key , options [ key ] ) ) : acc ; } , { } ) ; var args = _extends ( { outputPath : process . cwd ( ) , outputDest : 'critical.css' , preserve : true , minify : true , dryRun : false } , filteredOptions ) ; append = false ; return function ( css ) { var dryRun = args . dryRun , preserve = args . preserve , minify = args . minify , outputPath = args . outputPath , outputDest = args . outputDest ; var criticalOutput = ( 0 , _getCriticalRules . getCriticalRules ) ( css , outputDest ) ; return Object . keys ( criticalOutput ) . reduce ( function ( init , cur ) { var criticalCSS = _postcss2 . default . root ( ) ; var filePath = _path2 . default . join ( outputPath , cur ) ; criticalOutput [ cur ] . each ( function ( rule ) { return criticalCSS . append ( rule . clone ( ) ) ; } ) ; return ( 0 , _postcss2 . default ) ( minify ? [ _cssnano2 . default ] : [ ] ) // @TODO Use from/to correctly. . process ( criticalCSS , { from : undefined } ) . then ( dryRunOrWriteFile . bind ( null , dryRun , filePath ) ) . then ( clean . bind ( null , css , preserve ) ) ; } , { } ) ; } ; }
Primary plugin function.

@param {object} options Object of function args.
@return {function} function for PostCSS plugin.
Primary plugin function .