Deploy Angular 2 with Azure Webapp

前端 未结 6 925
感动是毒
感动是毒 2020-12-05 05:38

How can can I deploy an angular 2 webapp to azure? I guess I need some type of final compilation script.

Thanks in advance.

6条回答
  •  误落风尘
    2020-12-05 06:35

    In order to run angular2 app in azure follow these steps:

    1. create a new ng app (with ng cli) : ng new testApp and push to some github repo.
    2. create Azure deployment files for Kudu :
    npm install azure-cli -g
    azure site deploymentscript --node
    

    this will create 2 files .deployment and deploy.cmd

    1. edit the deploy.cmd remove the --production from the line

    :: 3. Install npm packages

    so that all dependencies will be installed (including ng cli)

    1. add under the section of :: 3. Install npm packages

    this snippet:

    echo Handling Angular build   
        :: 4. Build ng app
        IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
          pushd "%DEPLOYMENT_TARGET%"
          call :ExecuteCmd "!NODE_EXE!" ./node_modules/@angular/cli/bin/ng build --prod --env=prod --aot
          IF !ERRORLEVEL! NEQ 0 goto error
          :: the next line is optional to fix 404 error see section #8
          call :ExecuteCmd cp "%DEPLOYMENT_TARGET%"/web.config "%DEPLOYMENT_TARGET%"/dist/
          IF !ERRORLEVEL! NEQ 0 goto error
          popd
        )
    
    1. create a new webapp in azure and bind it to your github repository
    2. now just change the root of the app in the Azure "Application Settings"
      under "Virtual applications and directories"
      from

    site\wwwroot


    to

    site\wwwroot\dist


    7. trigger a deployment. (by pushing to github or manually from the azure portal)
    8. (optional) for fixing the 404 when refreshing, you need to add a web.config on the root with this content:

       
        
          
            
              
                
                  
                  
                    
                    
                  
                  
                
              
            
          
        
    
    1. open your app .. BOOM!

提交回复
热议问题