Closed tillsanders closed 6 years ago
You should use the normaliser callback to map from module name to filepath, then you can interpret relative paths in subsequent calls correctly.
See https://gist.github.com/stesie/c9143b98355295420470 for a Node.js module loader implementation. (that at least can load .js files; fails on .json files though)
Might as well try this:
I've been trying to implement my own module loader (simulating the behaviour of node) using
setModuleLoader()
andsetModuleNormaliser()
. The callback I wrote forsetModuleNormaliser()
gets two arguments:Now, if the required path is relative (e.g.
./some-sub-module.js
), I have no way of finding this required file because my callback only knows the base path of the current module, but not the path of the current file.