provide a configuration to customize some aspects of the returned loader function.
a url loader function that can be passed to the callback of EsbuildPluginBuild.onLoad | esbuild.PluginBuild.onLoad
,
so that it can fetch the contents of url-based paths when esbuild intercept
a factory function that returns a general purpose url content loading function for your esbuild plugin, tuned to your specific
config
.for the content to be correctly fetched and loaded, your
args.path
must be in one of the following formats:"http://"
or an"https://"
url"file://"
url"/home/bin/..."
or"C:/Users/..."
)make sure that the path is not a relative path (even if it's relative to the current working directory).
esbuild identifies redundant/duplicate resources by their resolved path and namespace . if the same resource is being bundled but with either a different resolved path, or under a different namespace, then esbuild will consider them to be separate resources, instead of being one and the same. thus, it is extremely crucial that you prepare a uniquely-idenfifiable resolved path in the plugin's resolver, rather than delaying its resolution in the plugin's loader.
in other words, for best results minifiable results, you should resolve the following things in the plugin's resolver, rather than the plugin's loader:
http://
orfile://
path)jsr:@scope/package/pathname
) should also be resolved to http paths.typically, the unique key that esbuild uses for identifiying redundant/duplicate resource references is of the following template:
${resolver_result.namespace}:${resolver_result.path}
where
resolver_result
is of kindesbuild.OnResolveResult
.this key also becomes the key of the resource in the output metadata object (if it is enabled).
based on some logging tests, I've verified that esbuild does indeed memorize the result of an
onLoad
's callback. this means that it is possible for inconsistencies to occur in yourpluginData
, when the dependency paths are being resolved. but I will say that it is hard to imagine if this could ever become an issue, since the dependencies will also be loaded only once . although, the next time something other than the original dependant, requires the same dependency file, the newpluginData
(i.e. potentially different) of the new dependant will not be conveyed to the loader (since its results are cached by esbuild).