[英]webpack DefinePlugin process.env.NODE_ENV is undefined
I am not too good with front-end technologies... So if I have wrong expectations - please correct me or my code.我不太擅长前端技术......所以如果我有错误的期望 - 请纠正我或我的代码。 I have created a repository with code that allows to reproduce issue.
我创建了一个包含允许重现问题的代码的存储库。 Here is the link: https://github.com/ffatheranderson/webpack-issue-reproduction
这是链接: https://github.com/ffatheranderson/webpack-issue-reproduction
as described in readme.md of the project:如项目的 readme.md 中所述:
======================================== =========================================
npm run watch
command - the generated result/bundle.js
file to have such lines: npm run watch
命令后 - 生成的result/bundle.js
文件有这样的行:...
var _environment = 'development';
var _ANOTHER_VARIABLE = "another variable value";
...
npm run watch
command - the generated result/bundle.js
file contains such lines: npm run watch
命令后 - 生成的result/bundle.js
文件包含这样的行:...
var _environment = undefined;
var _ANOTHER_VARIABLE = "another variable value";
...
...
plugins: [
new webpack.DefinePlugin({
ENVIRONMENT: JSON.stringify(process.env.NODE_ENV),
ANOTHER_VARIABLE: JSON.stringify("another variable value"),
})
]
...
in webpack.config.js
file.在
webpack.config.js
文件中。
As you can see variable _environment
is not initialized with development
value as it is promised here: https://webpack.js.org/configuration/mode/正如您所看到的,变量
_environment
没有像这里所承诺的那样使用development
值初始化: https://webpack.js.org/configuration/mode/
======================================== =========================================
_environment
is undefined
because the environment variable NODE_ENV
is undefined. _environment
undefined
,因为环境变量NODE_ENV
未定义。 You can solve this in one of three:您可以通过以下三种方式之一解决此问题:
npm run watch --node-env=development
: https://webpack.js.org/api/cli/#node-envnpm run watch --node-env=development
: https://webpack.js.org/api/cli/#node-envNODE_ENV
in your current shell session:NODE_ENV
: $ export NODE_ENV=production; npm run watch
--env
argument, a file on disk, hard-coding it, etc.)--env
参数、磁盘上的文件、对其进行硬编码等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.