Reputation: 22993
Loaders in Node can be used to hook into the module loading process, intercepting import
or require
calls. This works fine, but sometimes you might want to use multiple loaders. For instance, you are using some loader based on ESBuild, ts-node or SWC to load your "normal" test code, but then you figure out you also want to use Quibble to intercept some calls for certain ESM modules.
Currently, using multiple loaders is not directly supported, although work is underway, so I am wondering how to achieve this today using workarounds. I guess one would somehow write a wrapper to delegate between different loaders, alternatively feed the output of one into another?
I see the API for loaders seem manageable, but any practical hints on achieving this is appreciated :)
Upvotes: 1
Views: 755
Reputation: 22993
Seems like I was wrong in saying you could not use multiple loaders today. It is just that the API (as it always has been) is marked experimental and unstable. You can regard it as a chain of handlers feeding into each other, just as with require
:
node \
--experimental-loader unpkg \
--experimental-loader http-to-https \
--experimental-loader cache-buster
This answer is incomplete, so will add to it (or someone else can edit it) when I know more.
Upvotes: 0