【问题标题】:Tasks "block" each other任务相互“阻塞”
【发布时间】:2015-04-06 11:26:15
【问题描述】:

我在 Grunt 中发现了一个奇怪的行为,两个任务似乎相互阻塞(或类似的东西)。任务是:shell (https://github.com/sindresorhus/grunt-shell) 和 sass (https://github.com/gruntjs/grunt-contrib-sass)。

我的(简化的)Gruntfile;

"use strict";

var path        = require('path');

module.exports = function(grunt) {

    require('time-grunt')(grunt);

    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        shell: {
            options: {
                stdout: true,
                stderr: true
            },
            bower: {
                command: path.resolve(process.cwd() + '/node_modules/.bin/bower --allow-root install')
            }
        },

        /* ... other tasks */

        sass: {
            dist: {
                options: {
                    trace: true
                },

                files: {
                    'dist/additional.css': 'assets/stylesheets/additional.scss'
                }
            }
        }
    });

    grunt.registerTask('default', [
        'shell',
        'sass',
    ]);

}

当我启动 grunt 时,我的 shell 任务已完成,但咕噜声“停止”在 shell 任务:

Running "shell:bower" (shell) task

Running "sass:dist" (sass) task

### ctrl + c ###

Execution Time (2015-04-06 10:56:14 UTC)
loading tasks         8.9s  █ 1%
shell:bower          18.6s  ██ 2%
sass:dist        13m 25.2s  ██████████████████████████████████████████████ 97%
Total 13m 52.7s

当我分别开始这些任务时(分别使用grunt shellgrunt sass)一切正常。

有什么想法吗?谢谢!

【问题讨论】:

标签: node.js gruntjs


【解决方案1】:

切换 grunt-shell 为它的 fork grunt-shell-spawn 并尝试同步运行任务。

shell: {
  options: {
    stdout: true,
    stderr: true,
    async: false
  },
  bower: {
    command: path.resolve(process.cwd() + '/node_modules/.bin/bower --allow-root install')
  }
}

【讨论】:

  • 只需切换到 grunt-shell-spawn 而不是 grunt-shell 我的问题就解决了 :) 非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-16
  • 1970-01-01
  • 2019-01-06
  • 2011-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多