Adding compiler sources
By default, bud.js only resolves source code from the @src
directory.
Nearly all of the modules you install will have been compiled before they are published. It's almost always a waste to run this code through Babel or whatever other compiler you may be using.
Nevertheless, some packages expect to be compiled from source. We can allow for this with the bud.build.rules API.
Common examples:
- highlight.js
- swiper
- various scss frameworks
- a project that needs to source modules from multiple directories
Adding sources
Use bud.compilePaths to add additional directories to the list of sources that will be compiled.
As a quick example, let's say we have a project that needs to source modules from the swiper package.:
- TS
- JS
- YML
- JSON
bud.config.ts
import type {Bud} from '@roots/bud'
export default async (bud: Bud) => {
bud.compilePaths([
bud.path(`@src`),
bud.path(`@modules/swiper`)
])
}
bud.config.js
/** @param {import('@roots/bud').Bud} bud */
export default async (bud) => {
bud.compilePaths([
bud.path(`@src`),
bud.path(`@modules/swiper`)
])
}
bud.config.yml
compilePaths:
- ['src', 'node_modules/swiper']
bud.config.json
{
"compilePaths": [
["src", "node_modules/swiper"]
]
}