Skip to main content

bud.make

Create a new, configurable instance of Bud.

For more context on how this might be useful check out the guide on multi-instance configurations.

Usage

bud.make is an asyncronous function that takes two parameters:

  • The label of the new compiler, or a context to be used when constructing the new instance.
  • An optional configuration callback

Example specified with a label:

export default async bud => {
await bud.make('compiler-a', async child => child.entry('app', 'app.js'))
}

Example specified with context overrides:

export default async bud => {
await bud.make(
{
label: 'compiler-b',
basedir: bud.path('./compiler-b'),
},
async child => {
child.entry('app', 'app.js')
},
)
}

Preventing runtime conflicts

When loading output from multiple instances on a single page you need to be aware of the potential for runtime conflicts.

If you are using the bud.runtime function, you likely want to use the value single (the default value).

Beyond that, it may be helpful to know that each instance of bud.js declares all previous instances as dependencies. So, in the above examples, compiler-a would be a dependency of compiler-b. If you added another instance, compiler-c, it would be dependent on both compiler-a and compiler-b.

You can modify this behavior by declaring your own dependencies using the dependsOn context prop.

export default async bud => {
await bud.make({
label: 'compiler-a',
basedir: bud.path('./compiler-a'),
})

await bud.make({
label: 'compiler-b',
basedir: bud.path('./compiler-b'),
})

/**
* By default `compiler-c` would depend on `compiler-a` and `compiler-b`.
* By specifying a value `dependsOn` we can override this behavior.
*/
await bud.make({
label: 'compiler-c',
basedir: bud.path('./compiler-c'),
dependsOn: ['compiler-a'],
})
}

You can also modify this behavior with the build.dependencies hook:

bud.get('compiler-c').hooks.on('build.dependencies', ['compiler-a'])

Related:

Guides: