The global variable of webpeack configuration is undefined?

//webpack :
if(env.production) {
    plugins.push(
      new MiniCssExtractPlugin({
        filename: path.posix.join(__dirname, "../dist/style.css")
      }),
      new webpack.DefinePlugin({
        "process.env": {
          NODE_ENV: ""production""
        }
      })
    )
  }
  console.log("="+process.env.NODE_ENV)

Picture description
the value is assigned by DefinePlugin, and the value is displayed as undefined,. I don"t know what happened.

Apr.09,2021

first of all, please read the DefinePlugin documentation carefully.

now I assume you have read it. DefinePlugin is used to replace constants in the code, such as const a = SOME_CONST in the code, and DefinePlugin ({SOME_CONST:'"hello"'}) in your configuration file, then the code will be replaced with const a = "hello" , so quotation marks are very important here.

so you can see how inexplicable it is for you to output the definition directly in the configuration file without looking at the document.

as for how to handle errors, it depends on how you use them in your code. It is recommended that you find the corresponding line and adjust the configuration according to your code.


console.log('='+process.env.NODE_ENV)

the above code is put into your business code

Menu