[英]Webpack mode production NODE_ENV still undefined
I'm trying to work with webpack 4 and a tutorial. 我正在尝试使用webpack 4和一个教程。 I could set up a project, but it seems the setting for 我可以建立一个项目,但似乎
process.env.NODE_ENV
if running webpack via "webpack --mode production" is still undefined. 如果通过“ webpack --mode production”运行webpack仍未定义。 I don't understand how to make the loader evaluate the correct mode to extractcss in seperate files or not: 我不明白如何使加载程序评估正确的模式以提取单独文件中的文件或不提取:
const styles = {
test: /\.(sa|sc|c)ss$/,
use: [
{loader: process.env.NODE_ENV !== 'production' ? 'style-loader' : miniCssExtractPlugin.loader},
{loader:'css-loader'},
{loader:'sass-loader'}
]
}; };
If I hardcode it to "production" it does work, but I want to be able to select it via webpack --mode! 如果我将其硬编码为“生产”,那么它确实可以工作,但是我希望能够通过webpack --mode选择它! Isn't that possible? 那不可能吗?
If I hardcode it to "production" it does work, but I want to be able to select it via webpack --mode! 如果我将其硬编码为“生产”,那么它确实可以工作,但是我希望能够通过webpack --mode选择它! Isn't that possible? 那不可能吗?
Unfortunately, this is one of the complanies of many loaders/plugins authors. 不幸的是,这是许多加载程序/插件作者的抱怨之一。 NODE_ENV is not set based on the type of mode that you are running. 未根据您所运行的模式类型设置NODE_ENV。 One of the problems here is that it is not possible to update node options/flags after the process has already started. 这里的问题之一是,进程已经开始后就无法更新节点选项/标志。
You'll have to manually set cross-env NODE_ENV=production webpack --mode
(cross-env is a env setter, that works on windows and unix). 您必须手动设置cross-env NODE_ENV=production webpack --mode
(cross-env是一个env设置程序,可在Windows和Unix上使用)。
您可以尝试使用SET NODE_ENV = production(如果从Linux进行操作,则可以导出而不是SET)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.