我正在尝试使用 webpack 在我们的网站上运行热开发服务器;该网站使用 ReactJS,其中包含以下代码:
if (\"production\" !== process.env.NODE_ENV) // etc
当不运行热插拔时,它没问题,但使用热插拔时,它会运行,导致错误:
TypeError: process.env is undefined
代码如下所示:
该项目仿照https://github.com/webpack/react-starter https://github.com/webpack/react-starter which does工作;所以问题是;我在配置文件中犯了什么错误和/或当“生产”编译工作正常时如何查找错误?
我已经发布了webpack 配置文件的要点 https://gist.github.com/haf/f671f1113d2c5dead5a7.
在你的 webpack 配置中,有两个选项会影响process.env
:
-
当您指定config.target https://gist.github.com/haf/f671f1113d2c5dead5a7#file-gistfile1-txt-L121 (see config.target http://webpack.github.io/docs/configuration.html#target)
- 当您定义process.env变量通过DefinePlugin https://gist.github.com/haf/f671f1113d2c5dead5a7#file-gistfile1-txt-L110
看看你的代码,它看起来像process.env
当两者都可能是未定义的options.prerender
and options.minimize
are false
.
您可以通过始终使用定义的环境来解决此问题process.env
(ex: node
),或者通过使用DefinePlugin
自己为变量分配默认值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)