JesseZhao1990 / blog

learing summary
MIT License
62 stars 7 forks source link

webpack之DefinePlugin使用经验总结 #105

Open JesseZhao1990 opened 6 years ago

JesseZhao1990 commented 6 years ago

首先贴一下官方文档: 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,可以写几套不同的配置文件,根据不同的环境加载不同的配置文件。两种方法都各有优劣。