bud.config
bud.js config files are the most straight forward way of interfacing with bud.js.
- The file name should include
bud
in the name. - The module should be located in the project root or the
./config
directory. - The module can be written in JavaScript, TypeScript, YML or JSON5.
- JavaScript and TypeScript configurations can either export a configuration function or import bud and use it directly.
By default bud.js uses esbuild-wasm to transpile the config file when authored with TypeScript.
If you prefer you can install esbuild and it will be preferred.
The esbuild team advises that using esbuild is faster than esbuild-wasm, but the benefit of esbuild-wasm is that it doesn't need to be built during installation.
Example configurations
- TS
- JS
- YML
- JSON
import type {Bud} from '@roots/bud'
export default async (bud: Bud) => {
bud.entry(`app`, [`app.js`, `app.css`])
}
/** @param {import('@roots/bud').Bud} bud */
export default async (bud) => {
bud.entry(`app`, [`app.js`, `app.css`])
}
entry:
- app
- ['app.js', 'app.css']
{
"entry": ["app", ["app.js", "app.css"]]
}
Importing bud.js directly
You can import bud.js directly and use it in your configuration.
- TS
- JS
import {bud} from '@roots/bud'
bud.entry(`app`, [`app.js`, `app.css`])
import {bud} from '@roots/bud'
bud.entry(`app`, [`app.js`, `app.css`])
Using multiple configuration files
It is possible to create more than one bud.js configuration file.
When more than one configuration file is present they are execuetd in the following order:
bud.*
- the standard, base configuration.bud.local.*
- local configuration.bud.{production,development}.*
- mode specific configuration. Applied whenbud.mode
matches.bud.{production,development}.local.*
- mode specific local configuration. Applied whenbud.mode
matches.
You may want to add bud.local.*
to your .gitignore
file. This way contributors to your project can make specific overrides using bud.local.*
files
without affecting the base configuration kept in source control.
Configuring bud.js with JSON and YML
Each key is a reference to a bud.js call. The supplied values are the arguments to that call, expressed as an array.
Calling functions
For example, the following bud.js configuration:
- YML
- JSON
entry:
- app
- app.js
{
"entry": ["app", "app.js"]
}
is equivalent to:
bud.entry('app', 'app.js')
There is some flexibility here if you are passing a single value and it is NOT an array. So, this is okay:
entry:
app: app.js
Since it can easily be interpreted by bud.js as:
entry:
- app: app.js
Which is equivalent to a single item in array of arguments, containing an object.
bud.entry({app: 'app.js'})
Conversely, since bud.assets expects an array, the following yml would cause an error:
# This is incorrect
assets: ['src/**/*.html', 'app/**/*.html']
How is bud.js to know whether you intended to pass multiple parameters or a single array? It can't, and so this is the result:
bud.assets('src/**/*.html', 'app/**/*.html') // wrong
// what we wanted: bud.assets(['src/**/*.html', 'app/**/*.html'])
To fix it, we must remember that we are passing an array of the function parameters, and wrap our argument in an array:
assets:
- ['src/**/*.html', 'app/**/*.html']
Accessing nested values
You can access nested properties with standard yml indentation:
babel:
setPluginOptions:
- '@babel/plugin-transform-runtime'
- {helpers: true}
You can also use dot notation:
babel.setPluginOptions:
- '@babel/plugin-transform-runtime'
- {helpers: true}