Grunt fails to run on Azure Web Site

前端 未结 1 2034
盖世英雄少女心
盖世英雄少女心 2020-12-15 12:45

I\'m trying to build and package my project using Azure\'s Git deployment.

I have created the following files

  • .deployment
相关标签:
1条回答
  • 2020-12-15 13:12

    This is a bit old, but I will answer it anyway just in case someone comes across this question.


    First, it is helpful to run grunt with colors disabled, as both the diagnostic console and the deployment logs struggle with the ANSI codes. To do this, run grunt --no-color. This should get the STDOUT information back into the Console and into the Deploy log.

    Second, I do not recommend using checked-in versions of Node or NPM. Windows Azure already has these build in to the environment, and already is configured for the special temporary paths and cache paths needed for both to execute at their best.

    Project Kudu is the deployment engine powering Azure Deployments, but you already know this, since you have a .deployment file. However, the Azure Command Line Tools [npm install azure-cli --global] will help you scaffold out some better deployment scripts that will use Azure's pre-installed Node and NPM setup.

    azure site deploymentscript –-node
    

    will get you that base node script.

    From there, a few modifications are needed to deploy.sh to get it to execute Grunt, reliably. Within deploy.sh is a #Deployment section. Replace its contents with the following:

    # Deployment
    # ----------
    
    echo Handling node.js grunt deployment.
    
    # 1. Select node version
    selectNodeVersion
    
    # 2. Install npm packages
    if [ -e "$DEPLOYMENT_SOURCE/package.json" ]; then
      eval $NPM_CMD install
      exitWithMessageOnError "npm failed"
    fi
    
    # 3. Install bower packages
    if [ -e "$DEPLOYMENT_SOURCE/bower.json" ]; then
      eval $NPM_CMD install bower
      exitWithMessageOnError "installing bower failed"
      ./node_modules/.bin/bower install
      exitWithMessageOnError "bower failed"
    fi
    
    # 4. Run grunt
    if [ -e "$DEPLOYMENT_SOURCE/Gruntfile.js" ]; then
      eval $NPM_CMD install grunt-cli
      exitWithMessageOnError "installing grunt failed"
      ./node_modules/.bin/grunt --no-color clean common dist
      exitWithMessageOnError "grunt failed"
    fi
    
    # 5. KuduSync to Target
    "$KUDU_SYNC_CMD" -v 500 -f "$DEPLOYMENT_SOURCE/dist" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
    exitWithMessageOnError "Kudu Sync to Target failed"
    

    This will run npm install, followed by bower install (if bower.json exists), followed by grunt clean common dist (if Gruntfile.js exists), and finally a KuduSync into your /wwwroot. (Note: replace 'clean common dist' with whatever Grunt tasks you need to run.)

    There are a few other issues you may run in to. I write this up in a post on my personal blog, which includes some of the issues you may run into.

    0 讨论(0)
提交回复
热议问题