简体   繁体   English

反应 | webpack | 在 Azure 上获取 process.env.NODE_ENV== undefined

[英]React | webpack | getting process.env.NODE_ENV== undefined on Azure

Used below scripts in package.json to set NODE_ENV while creating the build.在 package.json 中使用以下脚本在创建构建时设置 NODE_ENV。

"scripts": {
    "build-dev": "set NODE_ENV=development && webpack --config webpack.config.prod",
    "build-client": "set NODE_ENV=production && webpack --config webpack.config.prod",
}

locally if I run "npm run build-dev or build-client" its working correctly and able to read correct NODE_ENV on webpack.config.common.js file.如果我在本地运行“npm run build-dev or build-client” ,它工作正常并且能够在 webpack.config.common.js 文件上读取正确的 NODE_ENV。

But if I try same command to create build on Azure pipeline then process.env.NODE_ENV returning as undefined但是,如果我尝试使用相同的命令在 Azure 管道上创建构建,则process.env.NODE_ENV 返回未定义

Not sure on Azure why "process.env.NODE_ENV" returning as undefined.不确定 Azure 为什么“process.env.NODE_ENV”返回未定义。 Can someone please help to understand and what needs to be done on Azure to read correct NODE_ENV which was set at the Build time.有人可以帮助理解以及在 Azure 上需要做什么来读取在构建时设置的正确 NODE_ENV。

Below are the pipeline details以下是管道详细信息

# Node.js
# Build Data Direct UI project with npm.
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger: none
#- master

pool: AGENTS

variables:
  system.debug : true
  
steps:

- task: Docker@0
  displayName: 'Build an Image'
  inputs:
    azureSubscription: 'CIS-DEV-001-SC'
    azureContainerRegistry: `{"loginServer":"acrncusd.azurecr.io", "id" : "acrncusd"}`



- task: Docker@0
  displayName: 'Push Image'
  inputs:
    azureSubscription: 'CIS-DEV-001-SC'
    azureContainerRegistry: `{"loginServer":"acrncusd.azurecr.io", "id" :  
    "acrncusd"}`
    action: 'Push an image'
    imageName: `$(Build.Repository.Name):$(Build.BuildId)`

If you're using windows-hosted agent , we should remove the whitespace before and after the && .如果您使用的是windows-hosted agent ,我们应该删除&&前后的空格

Try:尝试:

"scripts": {
    "build-dev": "set NODE_ENV=development&&webpack --config webpack.config.prod",
    "build-client": "set NODE_ENV=production&&webpack --config webpack.config.prod",
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM