You are here

public function JsOptimizer::minifyJspacker in Advanced CSS/JS Aggregation 8.2

Minify a JS string using packer.

Parameters

string $contents: Javascript string.

array $asset: An asset.

File

advagg_js_minify/src/Asset/JsOptimizer.php, line 365

Class

JsOptimizer
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_js_minify\Asset

Code

public function minifyJspacker(&$contents, array $asset) {

  // Use Packer on the contents of the aggregated file.
  if (!class_exists('\\JavaScriptPacker')) {
    include drupal_get_path('module', 'advagg_js_minify') . '/jspacker.inc';
  }

  // Add semicolons to the end of lines if missing.
  $contents = str_replace("}\n", "};\n", $contents);
  $contents = str_replace("\nfunction", ";\nfunction", $contents);
  $packer = new \JavaScriptPacker($contents, 62, TRUE, FALSE);
  $contents = $packer
    ->pack();
}