bud.compilePaths
bud.compilePaths is used to specify directories which should be treated as source directories.
If you have errors which say something along the lines of You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
, this is probably the function you want to use to fix that!
By default, bud.js treats code outside of the @src
directory (likely modules downloaded via npm or yarn) as code that has already been bundled by some other means. This is a huge performance boost for your project! If that code was already compiled by the package author it would be a waste of time and energy to compile it again.
However, some authors may publish uncompiled source code with the expectation that you will transpile it as part of your build process. This function simplifies the process of configuring bud.js to handle these cases.
Usage
The most basic, broad and intensive application of this function is passing the project's base directory. This will treat every module as a source module.
export default async bud => {
bud.compilePaths(bud.path())
}
It pays to be more restrictive here. So while you could do the above it would be better to narrow it down:
export default async bud => {
bud.compilePaths([bud.path(`@src`), bud.path(`@modules`)])
}
Even better to only target the modules which actually need it:
export default async bud => {
bud.compilePaths([bud.path(`@src`), bud.path(`@modules/swiper`)])
}
The best possible thing would be to only treat the directories as sources for specific filetypes. This is supported with a second parameter:
export default async bud => {
bud.compilePaths(
/**
* For these directories...
*/
[bud.path(`@src`), bud.path(`@modules/swiper`)],
/**
* ...treat these filetypes as untranspiled
*/
[`js`, `css`],
)
}