Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Latest commit

 

History

History
42 lines (31 loc) · 1.74 KB

chapter08-production-builds.md

File metadata and controls

42 lines (31 loc) · 1.74 KB

Production builds

This is part of The Brunch.io Guide.

By default, Brunch runs in a development environment, or mode. This mostly means minification plugins (be it JS or CSS) don’t run (because the optimize setting defaults to false in development mode; which you can change, if you really want to).

You specify what environment to run in through the -e or --env CLI option, followed by the environment’s name. You can have any environments you want, with a special case for production, that is predefined with optimize set to true, and has its own CLI shortcut -P (or --production).

More importantly, you can alter settings based on the environment, through the root settings key overrides. In it, you can have one key per environment, each with replacements (overrides…) for any general settings you may have. The official docs use an example that actually reflects the default production settings:

overrides: {
  production: {
    optimize: true,
    sourceMaps: false,
    plugins: {autoReload: {enabled: false}},
  }
}

Personally I like my sourcemaps no matter what, so I would override defaults like so:

overrides: {
  production: {
    sourceMaps: true
  }
}

Please note that you don't have to use overrides to tweak your settings in development mode. This is Brunch's default mode, so there is nothing to override. You can just add your setting to the top level of your config file. To pick up the example from above and enable the optimize setting for development builds:

module.exports = {
  optimize: true
  // ...
}

« Previous: Using Brunch on a legacy codebase • Next: Watcher »