'How to run custom "npm run" command in VSBuild task Azure DevOps. Or am I doing something wrong?

I am setting up Azure Build and Publish pipelines for my company. I posted the yml file for the build pipeline in another question. See Here

One of the projects in my VS solution is a .Net 5.0 project with a React ClientApp folder. This is part of the package.json file in this React folder:

  "scripts": {
    "start": "env-cmd -f .env.localDevelopment react-scripts start",
    "build": "env-cmd -f .env.localDevelopment react-scripts build",
    "build_localdevelopment": "env-cmd -f .env.localDevelopment react-scripts build",
    "build_development": "env-cmd -f .env.development react-scripts build",
    "build_staging": "env-cmd -f .env.staging react-scripts build",
    "build_production": "env-cmd -f .env.production react-scripts build",
    ...
  },

The problem is that the VSBuild task in Azure Build pipeline automatically runs npm run build. I need a way to tell it to run one of these different scripts based off of the declared buildConfiguration variable. Is this possible?

If I can't do it from Azure is there a way to run a script in package.json that will automatically detect the build configuration, even outside of Azure?

Or am I doing this all wrong and need to follow a better pattern?

Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source