PHP code example of chenos / v8js-module-loader

1. Go to this page and download the library: Download chenos/v8js-module-loader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chenos / v8js-module-loader example snippets


make example

use Chenos\V8JsModuleLoader\ModuleLoader;

// entry directory
$loader = new ModuleLoader(__DIR__);

$loader->setExtensions('.js', '.json');

$loader->setEntryDir(__DIR__);

// array
$loader->addOverride(['vue' => 'vue/dist/vue.runtime.common.js']);

// key, value
$loader->addOverride('vue', 'vue/dist/vue.runtime.common.js');

// v8js version > 2.1.0+
$loader->addOverride(['fn' => function (...$args) {}]);
$loader->addOverride('obj', new stdClass());

$loader->addVendorDir(__DIR__.'/node_modules', __DIR__.'/bower_components');

$v8 = new V8Js();

$v8->setModuleNormaliser([$loader, 'normaliseIdentifier']);
$v8->setModuleLoader([$loader, 'loadModule']);