Skip to content

chenos/v8js-module-loader

Repository files navigation

V8Js ModuleLoader

Build Status Coverage Status

Requirements

  • PHP 7.0+
  • V8Js extension 2.0+

Installation

composer require chenos/v8js-module-loader

Dependents

Testing

make test

Example

make example

Access http://127.0.0.1:8888

Usage

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']);