The use of multiple loaders in Node
P粉986028039
P粉986028039 2023-08-09 16:52:21
0
1
660
<p>In Node, the loader can be used to hook into the module loading process and intercept the <code>import</code> or <code>require</code> statements. This feature is useful, but sometimes you may need to use multiple loaders. For example, you are using a loader based on ESBuild, ts-node or SWC to load your "normal" test code, but then you find that you also want to use Quibble to intercept calls to certain ESM modules. </p> <p>Currently, direct support for using multiple loaders is not possible, although work is in progress, so I would like to know how to achieve this with some workarounds. I guess one approach would be to write a wrapper to delegate between different loaders, or take the output of one loader as input to another? </p> <p>I see that the loader's API seems to be handleable, but any practical tips on how to achieve this would be appreciated :)</p>
P粉986028039
P粉986028039

reply all(1)
P粉523625080

It seems I was wrong when I said you can't use multiple loaders today. It's just that the API is (as it always has been) marked experimental and unstable. You can think of it as a series of handlers connected to each other, just like using require:

node \
  --experimental-loader unpkg \
  --experimental-loader http-to-https \
  --experimental-loader cache-buster

This answer is not complete yet, so I will add to it when I learn more (or someone else can edit it).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template