Skip to content

Commit

Permalink
feat: esbuild config option to modify build options (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine authored Dec 26, 2023
1 parent e44d329 commit 670eb37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export const unplugin = createUnplugin((options: UserOptions, meta) => {
// from file extension (eg: .js -> "js", .jsx -> 'jsx')
// loader?: (Loader | (code: string, id: string) => Loader)

// Read and/or modify build.initialOptions
// [https://esbuild.github.io/plugins/#build-options]
// config?: (initialOptions: BuildOptions) => void

// Or you can completely replace the setup logic
// setup?: EsbuildPlugin.setup,
},
Expand Down
3 changes: 3 additions & 0 deletions src/esbuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function getEsbuildPlugin<UserOptions = Record<string, never>>(

const context: UnpluginBuildContext = createEsbuildContext(initialOptions)

if (plugin.esbuild?.config)
plugin.esbuild.config.call(context, initialOptions)

if (plugin.buildStart)
onStart(() => plugin.buildStart!.call(context))

Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AstNode, EmittedAsset, PluginContextMeta as RollupContextMeta, Plugin as RollupPlugin, SourceMapInput } from 'rollup'
import type { Compiler as WebpackCompiler, WebpackPluginInstance } from 'webpack'
import type { Plugin as VitePlugin } from 'vite'
import type { Plugin as EsbuildPlugin, Loader, PluginBuild } from 'esbuild'
import type { BuildOptions, Plugin as EsbuildPlugin, Loader, PluginBuild } from 'esbuild'
import type { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core'
import type VirtualModulesPlugin from 'webpack-virtual-modules'

Expand Down Expand Up @@ -76,6 +76,7 @@ export interface UnpluginOptions {
onLoadFilter?: RegExp
setup?: EsbuildPlugin['setup']
loader?: Loader | ((code: string, id: string) => Loader)
config?: (options: BuildOptions) => void
}
}

Expand Down

0 comments on commit 670eb37

Please sign in to comment.