【问题标题】:Run grunt build command on Travis CI在 Travis CI 上运行 grunt build 命令
【发布时间】:2014-01-15 03:15:19
【问题描述】:

我正在使用 Travis CI 测试和构建我的项目,作为其中的一部分,我希望 travis 运行 grunt build 我尝试了以下但没有运气。

  • script: "grunt build"
  • script: "./node_modules/grunt build"
  • script: "./node_modules/grunt/grunt build"
  • script: "./node_modules/grunt/grunt.js build"

【问题讨论】:

    标签: node.js gruntjs travis-ci


    【解决方案1】:

    您是否确保在 Travis 节点上全局安装 grunt-cli

    我的 Travis CI 配置如下:

    language: node_js
    node_js:
      - "0.8"
    before_install: npm install -g grunt-cli
    install: npm install
    before_script: grunt build
    

    还有我的 package.json:

    {
        ...
        "scripts": {
            "test": "grunt test"
        },
        ...
    }
    

    我将解释 Travis 将执行的步骤流程:

    1. 要执行的第一步是before_install。我唯一的先决条件(除了 node.js)是grunt-cli,所以我使用这一步来安装它。
    2. 接下来是 install 步骤,在我的情况下,这将简单地安装我的 npm 模块
    3. 然后执行before script,运行grunt build
    4. 最后 Travis 会在 package.json 中寻找脚本,我指出测试步骤应该运行 grunt test

    我想指出,这是我自己对如何配置 Travis 的看法。我当然不倾向于你应该使用完全相同的方法。

    【讨论】:

    • @Anzeo 需要的所有其他 grunt 任务库是否应该是 devDependencies 或依赖项的一部分?我注意到我仍然收到构建错误说“未找到 npm 模块”,例如,对于“grunt-contrib-watch”
    • @theunexpected1 通常你所有的 grunt 任务都应该被列为开发依赖项。你确定 contrib-watch 列在 package.json 中吗?
    • @Anzeo,是的,当然。我还没有进一步调试,现在,我已经从 postinstall 过程中删除了 grunt build。我会再试一次,谢谢。
    【解决方案2】:

    您可能会错过 travis.yml 文件:

    before_script:
      - npm install -g grunt-cli
    

    然后“grunt whatever”应该可以正常执行(假设您在 package.json 的 devDependencies 中确实需要 grunt)。

    (见http://www.mattgoldspink.co.uk/2013/02/10/using-travis-ci-with-grunt-0-4-x/

    【讨论】:

      【解决方案3】:

      确保将 grunt 作为 devDependencies 的一部分。这是一个示例文件:https://github.com/fraxedas/raspi-cloud/blob/master/package.json

      "devDependencies": {
        "grunt": "^0.4.5",
        "grunt-contrib-jshint": "^0.11.2",
        "grunt-contrib-watch": "^0.6.1"
      }
      

      Travis-ci 将在安装步骤中安装 grunt:

      npm install 
      ...
      grunt@0.4.5 node_modules/grunt
      ...
      

      就我而言,我想用 grunt 运行 jshint。 这是我的 travis.yml 文件:https://github.com/fraxedas/raspi-cloud/blob/master/.travis.yml

      要集成 grunt,我只需要:

      before_script: grunt jshint
      

      您可以通过其他命令更改 jshint。

      【讨论】:

        【解决方案4】:

        我的 .travis.yml 看起来像这样:

        它的运行速度比npm 快得多,因为NodeJSpackage manager,我在这个例子中使用Yarn。它安装了yarngrunt clirubysass

        希望对您有所帮助。

        language: node_js node_js: - "7.1.0" before_install: - npm install -g yarn - yarn add global ruby - gem install sass install: - yarn add global sass - yarn add global grunt-cli - yarn add yarn install before_script: grunt

        【讨论】:

          猜你喜欢
          • 2015-08-24
          • 1970-01-01
          • 1970-01-01
          • 2014-04-03
          • 1970-01-01
          • 2016-02-19
          • 2018-02-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多