Adding transpiler sources
By default, bud.js only resolves source code from the @src
directory.
Nearly all of the modules you install will be transpiled before they are published. It's almost always a waste to run this code through Babel or whatever other transpiler you may be using.
Nevertheless, some packages expect to be transpiled from source. We can allow for this with the bud.build.rules API.
Common examples:
highlight.js
- various
scss
frameworks - a project that needs to source modules from multiple directories
Adding sources
You should make modifications to transpiler sources within a config.after
action.
Some extensions will not register build rules until after the config file is processed;
using this hook will guarantee that your customization takes precedence.
bud.hooks.action(`config.after`, async bud => {
bud.build.rules.js.setInclude([
bud.path('@src'),
bud.path('@modules/some-untranspiled-pkg'),
])
})
Or, you can be broad:
bud.hooks.action(`config.after`, async bud => {
bud.build.rules.js.setInclude([bud.path('@src'), bud.path('@modules')])
})
Apply the above change to all registered rules:
bud.hooks.action(`config.after`, async bud => {
Object.values(bud.build.rules).map(rule =>
rule.setInclude([bud.path('@src'), bud.path('@modules')]),
)
})
In general, we would advise being as restrictive as possible when it comes to whitelisting transpiler sources.