Skip to main content

bud.when

Executes a function if a given test is true.

  • The first parameter is the conditional check.
  • The second parameter is the function to run if true.
  • The third parameter is optional; executed if the conditional is not true.

Usage

Only produce a vendor bundle when running in production mode:

bud.when(bud.isProduction, () => bud.vendor())

Use eval sourcemap in development mode and hidden-source-map in production:

bud.when(
bud.isDevelopment,
() => bud.devtool('eval'),
() => bud.devtool('hidden-source-map'),
)

For clarity, here is a very verbose version of the same thing:

const test = bud.isDevelopment
const inProduction = () => bud.devtool('eval')
const inDevelopment = () => bud.devtool('hidden-source-map')

bud.when(test, inProduction, inDevelopment)