Skip to content

Commit

Permalink
fix: allow extending the js banner (#77)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Shay <[email protected]>
  • Loading branch information
y-nk and lukeshay authored Sep 15, 2023
1 parent 12619cc commit c205eb5
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/adapter/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ const DEFAULT_CONFIG: BuildOptions = {
target: "node16",
};

export const createEsBuildConfig = (entryFile: string, outDir: string, { esBuildOptions = {} }: Args) =>
mergeAndConcat(DEFAULT_CONFIG, esBuildOptions, {
banner: {
js: [
"import { createRequire as topLevelCreateRequire } from 'module';",
"const require = topLevelCreateRequire(import.meta.url);",
].join(""),
},
entryPoints: [entryFile],
format: "esm",
outdir: outDir,
outExtension: {
".js": ".mjs",
},
}) as BuildOptions;
export const createEsBuildConfig = (
entryFile: string,
outDir: string,
{ esBuildOptions = {} }: Args
) =>
mergeAndConcat(DEFAULT_CONFIG, esBuildOptions, {
banner: {
js: [
"import { createRequire as topLevelCreateRequire } from 'module';",
'const require = topLevelCreateRequire(import.meta.url);',
esBuildOptions.banner?.js ?? '',
].join(''),
},
entryPoints: [entryFile],
format: 'esm',
outdir: outDir,
outExtension: {
'.js': '.mjs',
},
}) as BuildOptions

export const bundleEntry = async (entryFile: string, outDir: string, args: Args) => {
await build(createEsBuildConfig(entryFile, outDir, args));
Expand Down

0 comments on commit c205eb5

Please sign in to comment.