Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Plugins now have access to a new API called
resolve
that runs esbuild's path resolution logic and returns the result to the caller. This lets you write plugins that can reuse esbuild's complex built-in path resolution logic to change the inputs and/or adjust the outputs. Here's an example:This plugin intercepts imports to the path
example
, tells esbuild to resolve the import./foo
in the directory/bar
, and then forces whatever path esbuild returns to be considered external. Here are some additional details:If you don't pass the optional
resolveDir
parameter, esbuild will still runonResolve
plugin callbacks but will not attempt any path resolution itself. All of esbuild's path resolution logic depends on theresolveDir
parameter including looking for packages innode_modules
directories (since it needs to know where thosenode_modules
directories might be).If you want to resolve a file name in a specific directory, make sure the input path starts with
./
. Otherwise the input path will be treated as a package path instead of a relative path. This behavior is identical to esbuild's normal path resolution logic.If path resolution fails, the
errors
property on the returned object will be a non-empty array containing the error information. This function does not always throw an error when it fails. You need to check for errors after calling it.The behavior of this function depends on the build configuration. That's why it's a property of the
build
object instead of being a top-level API call. This also means you can't call it until all pluginsetup
functions have finished since these give plugins the opportunity to adjust the build configuration before it's frozen at the start of the build. So the newresolve
function is going to be most useful inside youronResolve
and/oronLoad
callbacks.There is currently no attempt made to detect infinite path resolution loops. Calling
resolve
from withinonResolve
with the same parameters is almost certainly a bad idea.Fixes #641
Fixes #1652