【问题标题】:ASP.NET MVC run Gruntfile.js as part of build during Azure Kudu deploymentASP.NET MVC 在 Azure Kudu 部署期间运行 Gruntfile.js 作为构建的一部分
【发布时间】:2021-12-24 16:01:02
【问题描述】:

我们有 Gruntfile.js 文件,其中包含处理 css 和 js 文件的一系列任务,它使用本地计算机上的 Visual Studio Task Runner Explorer (/// <binding BeforeBuild='all' />) 运行文件。

如何在 Azure Web App Kudu 构建部署期间运行 Gruntfile.js 文件作为构建的一部分?

【问题讨论】:

    标签: asp.net-mvc azure azure-devops gruntjs kudu


    【解决方案1】:
    • 在禁用颜色的情况下运行 grunt,因为诊断控制台和部署日志都与 ANSI 代码有冲突。 运行grunt --no-color
    • Azure 命令行工具 [npm install azure-cli --global] 将帮助您搭建一些更好的部署脚本,这些脚本将使用 Azure 的预安装节点和 NPM 设置。
    • 需要对deploy.sh 进行一些修改,以使其能够可靠地执行 Grunt。 deploy.sh 内有一个#Deployment 部分。
    azure site deploymentscript –-node
    
    • 对于 Grunt 部署,我们将执行一个 Shell 脚本,该脚本将执行 npm、Bower 和 Grunt 命令,以使我们的代码可以投入生产。
    # 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"
    

    这将运行 npm install,然后是 bower install(如果 bower.json 存在),然后是 grunt clean common dist(如果 Gruntfile.js 存在),最后是 KuduSync 到您的 /wwwroot

    注意:将“clean common dist”替换为您需要运行的任何 Grunt 任务。

    请参考Grunt Deploy to Windows Azure

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多