简体   繁体   中英

ASP.NET MVC run Gruntfile.js as part of build during Azure Kudu deployment

We have Gruntfile.js file containing series of tasks which does processing for css & js files, it runs file using Visual Studio Task Runner Explorer ( /// <binding BeforeBuild='all' /> ) on local machine.

How to run Gruntfile.js file as part of build during Azure Web App Kudu build deployment?

  • Run grunt with colors disabled, as both the diagnostic console and the deployment logs struggle with the ANSI codes. run grunt --no-color
  • 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.
  • A few modifications are needed to deploy.sh to get it to execute Grunt, reliably. Within deploy.sh is a #Deployment section.
azure site deploymentscript –-node
  • For Grunt deployment, we are going to execute a Shell Script that will perform npm, Bower, and Grunt commands in an effort to make our code production-ready.
# Deployment
# ----------

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.

Please refer Grunt Deploy to Windows Azure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM