Environment configuration allows us to include or not include certain things in the build given certain configuration options. For example, we probably want to not include live reload for production builds, for this we need to have different environments. When building, we can provide an environment flag option. So lets go ahead and configure things to support this.
1 | yarn add --dev broccoli-env@^0.0.1 |
Note, the broccoli-stew
package also comes with an env
utility, with a slightly different API, but it doesn't expose
the environment name, and I want to be able to print it to the console, so I'm using the broccoli-env
package instead.
1 | // Brocfile.js |
What we've done here is wrapped the debug
and LiveReload
section in an env === "development"
, this ensures the
debug
and LiveReload
trees are not included in the build when making a production build.
In order to pass in a different environment, simply add BROCCOLI_ENV=production
before the build command, e.g.
BROCCOLI_ENV=production broccoli build dist
. To make this simpler, lets add a new run command in package.json
:
1 | { |
Now, running yarn build-prod
will build in "production" mode.
Completed Branch: 11-environment
Next: 12-minify