在Azure Web App/内置Azure DevOps中的javascript中配置设置 [英] Configuring settings in javascript in Azure Web App / built in Azure DevOps
问题描述
说我有一个js(普通,香草非节点js)文件,该文件的顶部包含这样的设置:
Say I have a js (plain, vanilla non-node js) file, that includes a setting at the top like this:
const API_ENDPOINT = 'https://somedomain-dev.azurewebsites.net/api/v1/';
在生产环境中运行时,我需要此值:
When running in production, I need this value instead:
const API_ENDPOINT = 'https://somedomain-prod.azurewebsites.net/api/v1/';
我可以想到两种方法,但不知道它们中的任何一种是否有效以及如何工作:
I can think of two approaches, but don't know if any of them would work and how:
- 在Azure Web App中配置它=>配置.最好将所有配置集中化.
- 在Azure Devops中的生成/发布过程中转换文件.(不确定如何)
有什么方法可以做到这一点?
What is a way to accomplish this?
推荐答案
在Azure Devops中的生成/发布过程中转换文件.
Transform the file during the build/release process in Azure Devops.
You can use PowerShell scripts to change files. Please add a PowerShell task in your build or release pipeline. Here is my sample:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$filePath = 'test.js'
$tempFilePath = "test1.js"
$find = 'https://somedomain-dev.azurewebsites.net/api/v1/'
$replace = 'https://somedomain-prod.azurewebsites.net/api/v1/'
(Get-Content -Path $filePath) -replace $find, $replace | Add-Content -Path $tempFilePath
Remove-Item -Path $filePath
Move-Item -Path $tempFilePath -Destination $filePath
您还可以尝试在市场中使用扩展名,例如文件创建者".它可以创建一个新文件并替换旧文件.
You can also try to use extensions in marketplace such as "File Creator". It can create a new file and replace the old one.
这篇关于在Azure Web App/内置Azure DevOps中的javascript中配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!