esbuild-node-loader icon indicating copy to clipboard operation
esbuild-node-loader copied to clipboard

Support file loader?

Open saitonakamura opened this issue 3 years ago • 1 comments

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

saitonakamura avatar Dec 06 '21 15:12 saitonakamura

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

loynoir avatar Mar 29 '22 06:03 loynoir