Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Support file loader? #28

Open
saitonakamura opened this issue Dec 6, 2021 · 1 comment
Open

Support file loader? #28

saitonakamura opened this issue Dec 6, 2021 · 1 comment

Comments

@saitonakamura
Copy link

saitonakamura commented Dec 6, 2021

I use it in pair with uvu to transpile typescript. When I'm trying to test a file than imports, for instance, a png file (which is set up as --loader:.png=file in my esbuild cli), node throws with

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".png" for /blabla/star.png
    at defaultGetFormat (internal/modules/esm/get_format.js:71:15)
    at getFormat (file://node_modules/esbuild-node-loader/loader.mjs:162:10)

It's obviously not a problem of this loader, but I'm stuggling to understand how to properly apporach it. Since esbuild supports file loader, maybe it makes sense to somehow support it inside this loader? Or it's better to chain loaders via https://github.com/lukeed/loadr and provide some fake one for certain extensions. I'd appreciate some guidance

@loynoir
Copy link
Contributor

loynoir commented Mar 29, 2022

@saitonakamura
AFAIK,

  1. Similar thing

http protocol

https://github.com/antfu/esbuild-node-loader/blob/main/loader.mjs#L100

add new extension .mts

https://github.com/antfu/esbuild-node-loader/blob/main/loader.mjs#L10

  1. There is not yet able to chain loaders, written nodejs v1 and v2 api loader api

Oh, that was dumb of me to assume it worked. I only tested with a single loader.
Thanks, will revisit later. Hopefully it'll be part of the redesign.

  1. Maybe someone can chain up multiple custom loader api, expose to one v2 loader api? Have't seen one yet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants