Skip to content

Commit

Permalink
feat: allow banner and footer to a function
Browse files Browse the repository at this point in the history
which accepts `format` in the parameter
  • Loading branch information
egoist committed Mar 7, 2022
1 parent 5bd6819 commit 2521e9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/esbuild/index.ts
Expand Up @@ -123,6 +123,15 @@ export async function runEsbuild(
...(options.esbuildPlugins || []),
]

const banner =
typeof options.banner === 'function'
? options.banner({ format })
: options.banner
const footer =
typeof options.footer === 'function'
? options.footer({ format })
: options.footer

try {
result = await esbuild({
entryPoints: options.entry,
Expand All @@ -134,8 +143,8 @@ export async function runEsbuild(
jsxFragment: options.jsxFragment,
sourcemap: options.sourcemap ? 'external' : false,
target: options.target,
footer: options.footer,
banner: options.banner,
banner,
footer,
tsconfig: options.tsconfig,
loader: {
'.aac': 'file',
Expand Down
11 changes: 9 additions & 2 deletions src/options.ts
Expand Up @@ -16,6 +16,13 @@ export type DtsConfig = {
footer?: string
}

export type BannerOrFooter =
| {
js?: string
css?: string
}
| ((ctx: { format: Format }) => { js?: string; css?: string } | undefined)

/**
* The options available in tsup.config.ts
* Not all of them are available from CLI flags
Expand Down Expand Up @@ -106,8 +113,8 @@ export type Options = {
* @see https://esbuild.github.io/api/#metafile
*/
metafile?: boolean
footer?: BuildOptions['footer']
banner?: BuildOptions['banner']
footer?: BannerOrFooter
banner?: BannerOrFooter
/**
* Target platform
* @default `node`
Expand Down

0 comments on commit 2521e9f

Please sign in to comment.