Abstract
Abstract
extractthis abstract method is supposed to consume the provided raw content and return back the object ContentDependencies that describes the list of dependencies, in addition to providing a unique immutable key for each dependency path (so that it can be recognized and re-injected after being transformed by esbuild).
the actions of this function should be invertible by the insertDeps method.
Abstract
insertthis abstract method is supposed to consume the provided dependencies object
and merge/inject them back into the dependencies.content
.
effectively, this function is supposed to invert the actions of the extractDeps method.
an overloadable method that should return a javascript-code string that exports the provided content parameter in the form of export const content = ...
.
by default, the baseclass GenericLoader escapes all characters of the content
parameter,
so that the string is perfectly preserved after the virtual module's evaluation.
this is achieved by using String.raw
and escaping all dollarsigns ("$") and backticks ("`") with template expressions.
however, such a thing may not be desirable, and you may want the evaluation of the template expressions within your content
, rather than suppressing it.
or you may wish to introduce additional functions to the script so that it evaluates the output content through a series of transformations.
in such cases, you would want to overload this method to suit your transformations needs.
but make sure to always export
variable named content
.
this method parses the provided raw_content parameter,
extracts its dependencies by calling the extractDeps method,
and then converts it to an equivalent javascript code that can be consumed and analyzed by esbuild
.
the generated javascript code looks like the following:
export const importKeys = []
globalThis.start_of_imports()
importKeys.push("key_1")
await import("path_1")
// ...
importKeys.push("key_N")
await import("path_N")
globalThis.end_of_imports()
export const content = `${ORIGINAL_RAW_CONTENT}`
this method unparses the esbuild-bundled javascript code generated by parseToJs, and analyzes the transformed paths of the imported dependencies, and then injects back the transformed paths back to the original raw contents through the insertDeps method.
the base class for creating custom loaders for any file type that is natively unsupported by
esbuild
.