-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Description
Hello, folks!
The whole story with ESM HTTPS Modules got me to a point where I am about to write custom loader for node. And I have one little issue with it (but maybe I am wrong?). I need to write a loader that will handle the whole import process of all types (builting, external .js, etc.)?
Why can't I write one specific loader that will extend node.js import policy rather than replace it?
If I could I'd like to write my specific loader like this:
node-https-loader.js
:
export function test(specifier): boolean {
return specifier.startsWith('https:');
}
export function resolve(specifier, parentModule, defaultResolve) {
// Will be called only if test() above returns `true`
}
In addition to resolve
function we have test
also. With the latter we can test the specifier
to see if it can be resolved with the given loader.
To optimize loading time any custom loaders could be tested after builtin modules, relative files, absolute files, checks.
This approach could give developers flexibility to use multiple custom loaders (e.g. yml
and https
at the same time)
I know that it breaks existing loaders idea but maybe we can do something about it?
If you like this idea I can invest my time to create PR
Thanks,
Viktor Ku