There are currently three loader hooks:
-
resolve: Takes a specifier (the string afterfromin animportstatement) and converts it into an URL to be loaded. -
load: Takes the resolved URL and returns runnable code (JavaScript, Wasm, etc.) as well as the name of one of Node’s ESM loader’s “translators”:commonjsmodulebuiltin(a Node internal module, likefs)json(with--experimental-json-modules)wasm(with--experimental-wasm-modules)
globalPreload: Defines a string of JavaScript to be injected into the application global scope.
Custom loaders are intended to chain to support various concerns beyond the scope of core, such as build tooling, mocking, transpilation, etc.
We plan to support chaining via what we’re calling the Chaining Hooks “Middleware” Design.
The initial experimental implementation consisted of 5 hooks:
resolvegetFormatgetSourcetransformSourcegetGlobalPreloadCode
These were consolidated (in nodejs/node#37468) to avoid counter-intuitive and paradoxical behaviour when used in multiple custom loaders.