Same name in other branches
  1. 5.0.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJspacker()
  2. 8.x-3.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJspacker()
  3. 8.x-4.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJspacker()

Minify a JS string using packer.

Paramètres

string $contents: Javascript string.

Fichier

advagg_js_minify/src/Asset/JsMinifier.php, line 233

Classe

JsMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_js_minify\Asset

Code

public function minifyJspacker(&$contents) {
    // Use Packer on the contents of the aggregated file.
    if (!class_exists('\\JavaScriptPacker')) {
        include $this->moduleExtensionList
            ->getPath('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();
}