- PHP 7.0+
- V8Js extension 2.0+
composer require chenos/v8js-module-loader
make test
make example
Access http://127.0.0.1:8888
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']);