简体   繁体   中英

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

Used below scripts in package.json to set NODE_ENV while creating the build.

"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.

But if I try same command to create build on Azure pipeline then process.env.NODE_ENV returning as undefined

Not sure on Azure why "process.env.NODE_ENV" returning as undefined. 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.

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 && .

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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