首先贴一下官方文档:
The DefinePlugin allows you to create global constants which can be configured at compile time. This can be useful for allowing different behavior between development builds and release builds. If you perform logging in your development build but not in the release build you might use a global constant to determine whether logging takes place. That's where DefinePlugin shines, set it and forget it rules for development and release builds.
首先贴一下官方文档: The DefinePlugin allows you to create global constants which can be configured at compile time. This can be useful for allowing different behavior between development builds and release builds. If you perform logging in your development build but not in the release build you might use a global constant to determine whether logging takes place. That's where DefinePlugin shines, set it and forget it rules for development and release builds.
简单的说就是可以利用这个区分不同的环境,想在不同的环境干不同的事情,可以定义通过webpack定义一个全局变量并且给其赋值来区分。区分不同环境的另一个常用方案是webpack的alias,可以写几套不同的配置文件,根据不同的环境加载不同的配置文件。两种方法都各有优劣。