ComponentInstaller\Process\RequireJsProcess::requireJs PHP Method

requireJs() public method

Constructs the require.js file from the provided require.js JSON array.
public requireJs ( array $json = [] ) : string
$json array The require.js JSON configuration.
return string The RequireJS JavaScript configuration.
    public function requireJs(array $json = array())
    {
        // Encode the array to a JSON array.
        $js = JsonFile::encode($json);
        // Construct the JavaScript output.
        $output = <<<EOT
var components = {$js};
if (typeof require !== "undefined" && require.config) {
    require.config(components);
} else {
    var require = components;
}
if (typeof exports !== "undefined" && typeof module !== "undefined") {
    module.exports = components;
}
EOT;
        return $output;
    }

Usage Example

 /**
  * testRequireJs
  *
  * @dataProvider providerRequireJs
  * @param array $json
  * @param string $expected
  */
 public function testRequireJs(array $json = array(), $expected = '')
 {
     $result = $this->process->requireJs($json);
     $this->assertEquals($expected, $result);
 }