1

I'm using Azure CI/CD pipelines to deploy a .NET/Angular app to Dev and Prod environments. I would like the application to be debuggable in the browser in only the Dev environment i.e. soureMap = true, optimization = false.

In the build pipeline, a single artefact is built, and then deployed to each environment in dedicated stages. It seems the build configuration is set as 'production' during the creation of the artefact, so replacing tokens once it has been built does not allow me to make the Dev environment debuggable.

What options do I have to enable browser debugging for dev while disabling it for prod?

1
  • Hi @Caustix, Good day to you. Have you got a chance to check the answer below to use different configurations to build your app? In case that was not your case, please share more details such as your pipeline YAML definition to understand your current workflow. Thx. Commented Nov 7, 2024 at 10:09

1 Answer 1

0

We can only assume you were trying to deploy an Angular app on Azure Static Web Apps, as we are unable to know for sure what is the Azure service provider, not even from a tag in your post.

With that being said, you may try adding a development config in your angular.json as suggested here.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular-basic": {
...
      "architect": {
        "build": {
...
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "development": {
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          },
          "defaultConfiguration": ""
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular-basic:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular-basic:build:production"
            },
            "development": {
              "browserTarget": "angular-basic:build:development"
            }
          }
        },
...
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "angular-basic:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "angular-basic:serve:production"
            },
            "development": {
              "devServerTarget": "angular-basic:serve:development"
            }
          }
        }
      }
    }
  },
  "defaultProject": "angular-basic"
}
...

Also use different build commands against different environments for AzureStaticWebApp@0 task.

package.json

{
  "name": "angular-basic",
  "version": "1.0.0",
  "scripts": {
...
    "build-ui-prod": "ng build --configuration production",
    "build-ui-dev": "ng build --configuration development",
...
  },
...
}
variables:
- ${{ if eq(parameters.target_environment, 'production') }}:
  - name: env
    value: prod
- ${{ else }}:
  - name: env
    value: dev

jobs:
- job: build_and_deploy_job
  displayName: Build and Deploy Job
  pool:
    vmImage: ubuntu-latest
  variables:
  - group: VG-AzureWebAppStaticAngular
  steps:
  - task: AzureStaticWebApp@0
    inputs:
      azure_static_web_apps_api_token: $(API_TOKEN)
      # Repository/Build Configurations - These values can be configured to match your app requirements.
      # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
      app_location: "/" # App source code path
      api_location: "" # Api source code path - optional
      output_location: "dist/angular-basic" # Built app content directory - optional
      # End of Repository/Build Configurations
      deployment_environment: ${{ parameters.target_environment }}
      app_build_command: 'npm run build-ui-$(env)'

enter image description here

In case this is irrelevant to your current workflow, please share more details and consider adding correct tag(s) to engage insights from the experts in respective subcommunity.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.