There's no built-in module loading framework because it's difficult for a single framework to match a wide variety of different module loading use cases. The Duktape distributable includes several optional module loader frameworks, for example:
module-duktape | A Duktape 1.x compatible loader based on
CommonJS modules version 1.1.1,
with additional support for module.exports and a few Duktape specific
module object properties. The internals are documented in
modules.rst,
see How to use modules for examples.
This loader was a built-in in Duktape 1.x but was moved into an optional extra in Duktape 2.x. |
module-node | A Node.js modules compatible loader. See How to use Node.js-like modules for examples. |
You can also implement your own module loader from scratch: the above loaders are implemented using the Duktape public API with no special access to internals.
The module loaders provide a require()
function which allows
modules to be loaded as follows:
var mod = require('foo/bar'); mod.hello();
The loaders abstract actual module resolution/loading to user-provided hook(s) to allow the loader to be embedded in wide variety of environments. For example:
There's currently no support for ES2015 import/export and ES2015 modules.
There's a recommended (but not mandatory) C module convention which allows C modules to be loaded and initialized from DLLs: c-module-convention.rst.