Skip to content

Commit

Permalink
feat: ✨ added support for custom loaders #24
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 4, 2021
1 parent 8c41d6e commit ad3268e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function _transform(
filename: string,
options: TranspileOptions
): string {
const loaders = getLoaders(options)
const ret = transformSync(code, {
...commonOptions,
...(options.esbuild as TransformOptions | undefined),
Expand All @@ -71,20 +72,31 @@ function _transform(
return ret.code
}

function getLoaders(options: TranspileOptions) {
const ret = { ...loaders }
if (typeof options.esbuild?.loader == "object") {
for (const [e, l] of Object.entries(options.esbuild.loader))
ret[e] = l as Loader
}
return ret
}

function _bundle(
code: string,
filename: string,
options: TranspileOptions
): string {
const ext = path.extname(filename)

const loaders = getLoaders(options)

return buildSync({
...commonOptions,
platform: "node",
...(options.esbuild as BuildOptions | undefined),
...{
loader: loaders,
bundle: true,
platform: "node",
stdin: {
sourcefile: filename,
contents: code,
Expand Down

0 comments on commit ad3268e

Please sign in to comment.