In Grunt or Gulp, I used to define all the requirements myself, like: stuff should be minified only for production, livereload should be enabled only in dev server.
Webpack handles this on its own, via its -d
and -p
options, that toggle the loaders' minimize
mode (most loaders ship with their relevant minifiers), the devtool
and similar stuff (I don't know what exactly). Most of that "just works".
But on the other hand, there are some libraries that have a development and production mode. For example, React looks at process.NODE_ENV
, and if it's production
, it disables the propTypes
checking (which will be later stripped off by minifier as dead code, thus reducing bundle size). In Webpack, a common way to do this is to use the DefinePlugin
.
The problem is, that this plugin should be enabled only in the production build. Some people go as far as having 2 separate webpack configs because of that. This seems overkill, since most of the job is already done by webpack. I'd like to avoid this.
To find some better solution, I'd like to understand what exactly changes when I use the -d
or -p
option, and how does it affect all the loaders and plugins. I didn't find it documented anywhere. The existing documentation just mentions "debug mode" or "watch mode" without explaining what does it actually mean.
Note that I'm not asking for a do-this-and-that answer. A good, detailed explanation would be appreciated.