@@ -41,6 +41,12 @@ export interface EsbuildPluginBuild extends PluginBuild {
41
41
onTransform : ( options : OnTransformOptions , callback : OnTransformCallback ) => void
42
42
}
43
43
44
+ interface Loader {
45
+ options ?: OnLoadOptions
46
+ onLoadCb ?: Parameters < PluginBuild [ 'onLoad' ] > [ 1 ]
47
+ onTransformCb ?: OnTransformCallback
48
+ }
49
+
44
50
export function getEsbuildPlugin < UserOptions = Record < string , never > > (
45
51
factory : UnpluginFactory < UserOptions > ,
46
52
) : UnpluginInstance < UserOptions > [ 'esbuild' ] {
@@ -51,12 +57,7 @@ export function getEsbuildPlugin<UserOptions = Record<string, never>>(
51
57
const plugins = toArray ( factory ( userOptions ! , meta ) )
52
58
53
59
const setupPlugins : EsbuildPlugin [ 'setup' ] = async ( build ) => {
54
- const setup = buildSetup ( meta )
55
- interface Loader {
56
- options ?: OnLoadOptions
57
- onLoadCb ?: Parameters < PluginBuild [ 'onLoad' ] > [ 1 ]
58
- onTransformCb ?: OnTransformCallback
59
- }
60
+ const setup = buildSetup ( )
60
61
const loaders : Loader [ ] = [ ]
61
62
62
63
for ( const plugin of plugins ) {
@@ -139,20 +140,18 @@ export function getEsbuildPlugin<UserOptions = Record<string, never>>(
139
140
}
140
141
}
141
142
142
- function buildSetup ( meta : UnpluginContextMeta & { framework : 'esbuild' } ) {
143
+ function buildSetup ( ) {
143
144
return ( plugin : UnpluginOptions ) : EsbuildPlugin [ 'setup' ] => {
144
145
return ( _build ) => {
145
- const build = meta . build = _build as EsbuildPluginBuild
146
+ const build = _build as EsbuildPluginBuild
146
147
const context = createBuildContext ( build )
147
148
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build
148
149
149
150
const onResolveFilter = plugin . esbuild ?. onResolveFilter ?? / .* /
150
151
const onLoadFilter = plugin . esbuild ?. onLoadFilter ?? / .* /
151
-
152
152
const loader = plugin . esbuild ?. loader ?? guessLoader
153
153
154
- if ( plugin . esbuild ?. config )
155
- plugin . esbuild . config . call ( context , initialOptions )
154
+ plugin . esbuild ?. config ?. call ( context , initialOptions )
156
155
157
156
if ( plugin . buildStart )
158
157
onStart ( ( ) => plugin . buildStart ! . call ( context ) )
@@ -306,7 +305,7 @@ function buildSetup(meta: UnpluginContextMeta & { framework: 'esbuild' }) {
306
305
}
307
306
308
307
if ( plugin . esbuild ?. setup )
309
- return plugin . esbuild . setup ( meta . build )
308
+ return plugin . esbuild . setup ( build )
310
309
}
311
310
}
312
311
}
0 commit comments