Open s1owjke opened 1 year ago
You can completely customize loading behavior with plugins: https://esbuild.github.io/plugins/#on-load
If path was resolved using one of the resolveExtensions (for example ./util.inspect
resolved as /node_modules/object-inspect/util.inspect.js
), then path received in OnLoadArgs will not include extension.
So, I need to resolve it again in the onLoad callback, because there is no other way to do that, right?
Ah that's no good. Looks like this is happening because that package contains this in its package.json file:
"browser": {
"./util.inspect.js": false
},
Running onLoad
without the extension is not correct. I could change this to run onLoad
with the extension, but arguably esbuild just shouldn't even call onLoad
in that case because the package is using browser
to request that the file be treated as an empty file.
It's not good and also not fast at all to guess extension again in the callback.
According to the initial specification in this case we shouldn’t load ./util.inspect.js
at all, an approach to add extension in this specific case would be a workaround.
For example I'm building a frontend application. I want to load all assets with file loader.
At this moment I need to explicitly specify a loader for all used extensions, to do this I need to additionally traverse all files. As we can't use regular expressions for extensions, it would be nice to have something like this.
Here is an example of a webpack configuration from react-scripts package.