您可以通過使用Kudu API和PowerShell來實現。例如(的package.json是在wwwroot文件夾)
- 添加Azure中的PowerShell步/任務(腳本參數:-resourceGroupName VS-starain2-集團-webAppName tempappstarain -dir 「網站\ wwwroot的」 指令 「故宮安裝」 )
PowerShell腳本:
param(
[string]$resourceGroupName,
[string]$webAppName,
[string]$slotName="",
[string]$dir,
[string]$command
)
function Get-AzureRmWebAppPublishingCredentials($resourceGroupName, $webAppName, $slotName = $null){
if ([string]::IsNullOrWhiteSpace($slotName)){
$resourceType = "Microsoft.Web/sites/config"
$resourceName = "$webAppName/publishingcredentials"
}
else{
$resourceType = "Microsoft.Web/sites/slots/config"
$resourceName = "$webAppName/$slotName/publishingcredentials"
}
$publishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType $resourceType -ResourceName $resourceName -Action list -ApiVersion 2015-08-01 -Force
Write-Host $publishingCredentials
return $publishingCredentials
}
function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName, $slotName = $null){
$publishingCredentials = Get-AzureRmWebAppPublishingCredentials $resourceGroupName $webAppName $slotName
Write-Host $publishingCredentials.Properties.PublishingUserName
Write-Host $publishingCredentials.Properties.PublishingPassword
return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}
function RunCommand($dir,$command,$resourceGroupName, $webAppName, $slotName = $null){
$kuduApiAuthorisationToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppName $slotName
$kuduApiUrl="https://$webAppName.scm.azurewebsites.net/api/command"
$Body =
@{
"command"=$command;
"dir"=$dir
}
[email protected]($Body) | ConvertTo-Json
Write-Host $bodyContent
Invoke-RestMethod -Uri $kuduApiUrl `
-Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
-Method POST -ContentType "application/json" -Body $bodyContent
}
RunCommand $dir $command $resourceGroupName $webAppName
相關文章:Interacting with Azure Web Apps Virtual File System using PowerShell and the Kudu API
你也可以只部署node_modul通過使用Azure App Service Deploy將e文件夾和文件複製到Azure Web應用程序(選擇步驟/任務的3. *版本,請勿使用Web Deploy選項選中「發佈」選項。打包或foder:[node_module文件夾路徑])
整個構建包應包含所有依賴項,爲什麼要在構建結束時發佈不包含node_modules文件夾的構建包以便共享? –