search

Home  >  Q&A  >  body text

The use of multiple loaders in Node

<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粉986028039P粉986028039471 days ago645

reply all(1)I'll reply

  • P粉523625080

    P粉5236250802023-08-10 15:15:18

    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).

    reply
    0
  • Cancelreply