Closed TheLarkInn closed 8 years ago
+1
The build seems correct and V8Js working properly.
V8Js provides a require
API method to JS code that must be backed by a custom module loader. V8Js neither makes assumptions from where to load module code (file system, database, whatever) nor how the modules are structured (e.g. with node_modules
folders or whatever).
So yes, you need to (at least) provide a module loader (via $v8->setModuleLoader(<callable>)
) that resolves a module name to JavaScript source code. By default V8Js however does module path normalisation, that is if your entrypoint code does require('foo/bar')
and the module code in turn does (require('./baz'
) then the module loader PHP function is called with foo/baz
.
In case you'd like to override this normalisation behaviour you can override be providing another callable to $v8->setModuleNormaliser
If you're willing to load Node.js modules keep in mind that that can only work as long as all dependencies don't depend on core stuff or modules that need native code. You might want to check out a Gist of mine: https://gist.github.com/stesie/c9143b98355295420470 which shows how to compile coffeescript code with V8Js and run that afterwards
As I finally busted out php-v8js (5.6.10) I tried to use a CommonJS
require('parse5')
however the error message out of the box was as follows:Is this something the user has to implement themselves? I see some commonjs libs inside the src lib, however I wasn't sure if there was a build error or not.