You are here

protected function CssMinifier::minifyCssMin in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.3 advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::minifyCssMin()

Processes the contents of a stylesheet through CSSMin for minification.

Parameters

string $contents: The contents of the stylesheet.

Return value

string Minified contents of the stylesheet including the imported stylesheets.

1 call to CssMinifier::minifyCssMin()
CssMinifier::optimize in advagg_css_minify/src/Asset/CssMinifier.php
Optimize the asset's content.

File

advagg_css_minify/src/Asset/CssMinifier.php, line 109

Class

CssMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_css_minify\Asset

Code

protected function minifyCssMin($contents) {
  $cssmin = new CSSmin(TRUE);

  // Minify the CSS splitting lines after 4k of text.
  $contents = $cssmin
    ->run($contents, 4096);

  // Replaces @import commands with the actual stylesheet content.
  // This happens recursively but omits external files.
  $contents = preg_replace_callback('/@import\\s*(?:url\\(\\s*)?[\'"]?(?![a-z]+:)(?!\\/\\/)([^\'"\\()]+)[\'"]?\\s*\\)?\\s*;/', [
    $this,
    'loadNestedFile',
  ], $contents);
  return $contents;
}