Skip to content
Merged
Prev Previous commit
Next Next commit
Update doc/api/esm.md
Co-authored-by: Geoffrey Booth <[email protected]>
  • Loading branch information
giltayar and GeoffreyBooth authored May 2, 2023
commit c87c78c16c7404d692e837ed1eeea487938f56bf
6 changes: 3 additions & 3 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,10 @@ loaded file.

#### Overriding loader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this code? Can you add it to the examples in https://github.com/nodejs/loaders-test?

We should probably have an example that needs to use both resolve and load, so that we demonstrate how the two hooks work together. Ideally it would be as realistic a use case as possible.

Speaking of realistic examples, another “resolve-only” use case discussed in the design docs for the loaders API was to rewrite specifiers like lodash into URLs like https://esm.sh/lodash. Perhaps this might be a better example than this “overriding loader,” as it would presumably be a lot shorter of an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this code? Can you add it to the examples in https://github.com/nodejs/loaders-test?

I have (in my repo that I link to in the issue), but I can definitely copy it to https://github.com/nodejs/loaders-test.

Speaking of realistic examples, another “resolve-only” use case discussed in the design docs for the loaders API was to rewrite specifiers like lodash into URLs like https://esm.sh/lodash

The example I gave is very realistic as it is a simplification of import maps, where you can map bare specifiers to specific files. I can definitely use your use-case, but I think in terms of complexity, they're roughly the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this lands (hopefully...😊), I'll not only add this loader to the loaders-test, but also modify the http-loader and typescript-loader to not need resolvers.


The above two loaders hooked into the "load" phase of the module loader.
This loader hooks into the "resolution" phase. This loader reads an
The previous two loaders defined `load` hooks. This is an example of a loader
that does its work via the `resolve` hook. This loader reads an
`overrides.json` file that specifies which specifiers to override to another
url.
URL.

```js
// overriding-loader.js
Expand Down