Brunch operates on a set of assumptions about how your app is authored and compiled — this allows to make your configs drastically simpler and achieve faster build times.
Any Brunch project consists of the following:
package.json
, which lists the plugins you want Brunch to use, as well as your app's own dependenciesWhat Brunch does, in essence, is this:
That's all there is, really. While Brunch does assume your code is going to live under app/
and your assets under app/assets/
, and build result is put under public/
, you are by all means free to use your own structure. Just tell Brunch what it is.
The only required piece of configuration is telling Brunch which output files you want — and it couldn't be simpler:
module.exports = {
files: {
javascripts: {joinTo: 'app.js'},
stylesheets: {joinTo: 'app.css'}
}
}
This will concatenate all your javascript files into public/app.js
.
If you want a little more control, like splitting your app code from vendor files into separate bundles, that's just as easy:
module.exports = {
files: {
javascripts: {joinTo: {
'app.js': /^app/, // all code from 'app/',
'vendor.js': /^(?!app)/ // all BUT app code - 'vendor/', 'node_modules/', etc
}},
stylesheets: {joinTo: 'app.css'}
}
}
The Brunch config is declarative, not imperative — you tell Brunch what you want to get, not how to actually do it.