Skip to main content

@roots/bud-babel

Babel can be added by installing the @roots/bud-babel extension.

Installation

yarn add @roots/bud-babel --dev

Configuration

@roots/bud-babel comes configured with:

Presets

Presets are registered to bud.babel.presets.

bud.config.mjs
console.dir(bud.babel.presets)

Add a preset

It will be appended to whatever presets are already registered.

bud.config.mjs
bud.babel.setPreset('@babel/preset-env')

Remove preset

Use bud.babel.unsetPreset to remove a preset, if present.

bud.config.mjs
bud.babel.unsetPreset('@babel/preset-env')

Fully override preset configuration

Pass an array of presets to bud.babel.setPresets to fully replace the existing presents configuration.

bud.config.mjs
bud.babel.setPresets(['@babel/preset-env'])

Set options on a preset

bud.config.mjs
bud.babel.setPresetOptions('@babel/preset-env', {
useBuiltIns: 'entry',
})

Plugins

Managing plugins uses nearly the exact same API.

Add a plugin

bud.config.mjs
bud.babel.setPlugin('@babel/plugin-transform-runtime')

Add a plugin with options

bud.config.mjs
bud.babel.setPlugin(['@babel/plugin-transform-runtime', {helpers: false}])

Remove a plugin

bud.config.mjs
bud.babel.unsetPlugin('@babel/plugin-transform-runtime')

Override any plugin options

bud.config.mjs
bud.babel.setPluginOptions('@babel/plugin-transform-runtime', {
helpers: false,
})

Fully override plugins

bud.config.mjs
bud.babel.setPlugins([
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-object-rest-spread',
['@babel/plugin-syntax-dynamic-import', {helpers: false}],
])