Skip to main content

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

bud.compilePaths

There is a function to simplify this available in bud@6.9.0: bud.compilePaths.

You should make modifications to compiler sources within a build.before action. Some extensions may not register build rules until after the config file is processed; using this hook will guarantee that your customization takes precedence.

bud.hooks.action(`build.before`, async bud => {
bud.build.rules.js.setInclude([
bud.path('@src'),
bud.path('@modules/some-untranspiled-pkg'),
])
})

Or, you can be broad:

bud.hooks.action(`build.before`, async bud => {
bud.build.rules.js.setInclude([bud.path('@src'), bud.path('@modules')])
})

Apply the above change to all registered rules:

bud.hooks.action(`build.before`, 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.