Skip to main content

bud.make

Create a new, configurable instance of bud.js.

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 entrypoints from multiple instances within a single request 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).

If you are using a different value than single you may need to declare cross-instance dependencies.

For example, let's say we have an instance, compiler-a, that adds a value to the window object.

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

And now we have a second instance, compiler-b, which depends on the value added by compiler-a.

To avoid type errors and variable collisions will want to mark compiler-b as depending on compiler-a.

You can do that by including the dependsOn property in the instance context:

await bud.make({
label: `compiler-b`,
basedir: bud.path(`./compiler-b`),
dependsOn: [`compiler-a`],
})

Related:

Guides: