【问题标题】:grunt watch task block the command linegrunt watch 任务阻塞命令行
【发布时间】:2015-10-27 19:25:32
【问题描述】:

我是 grunt 的新手,还在学习,所以我遇到了一个非常奇怪的问题。 当我运行"watch" 任务时,我的命令行被阻塞了,所以基本上我什么也做不了。 请记住,任务已成功完成。 这是我的命令行输出:

C:\server\css-test>grunt w
Running "watch" task
Waiting...OK
>> File "compass-examples-master\02\sass\screen.scss" changed.

Running "compass" (compass) task
unchanged compass-examples-master/02/sass/ie.scss
unchanged compass-examples-master/02/sass/print.scss
overwrite compass-examples-master/02/stylesheets/new/sass/screen.css

Running "watch" task

Completed in 1.496s at Fri Mar 22 2013 19:31:37 GMT+0100 (Central Europe Standard Time) - Waiting...

如您所见,我所做的只是运行"compass" 任务,它成功完成。

插入点在Waiting... 文本部分之后一直闪烁,但键盘输入不起作用。

我的咕噜声配置

module.exports = function (grunt)
{

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        compass: {
            dist: {
                options: {
                    sassDir: 'compass-examples-master/02',
                    cssDir: 'compass-examples-master/02/stylesheets/new',
                    imagesDir: 'compas-examples-master/02/images',
                    boring: false,
                    outputStyle: 'nested',
                    require: 'sass-media_query_combiner'
                }
            }
        },
        watch: {
            files: 'compass-examples-master/02/sass/*',
            tasks: ['c']
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-compass');


    grunt.registerTask('c', 'compass');
    grunt.registerTask('w', 'watch');

};

【问题讨论】:

    标签: node.js command-line cmd watch gruntjs


    【解决方案1】:

    我没有使用过 grunt watch,但我认为问题在于它是一个持续运行的进程,默认情况下,您的命令行通常一次运行一个进程。您可以使用 3 种解决方案。

    1. 打开一个新终端。您可以同时打开多个,这将允许您将第二个用作主终端,而 grunt watch 占据另一个。
    2. 在命令中使用 & 符号。这将开始该过程并立即将命令行返回给您,允许您将其用于其他事情。您可以将其视为在后台运行命令。该进程仍然连接到终端窗口,因此如果您关闭该窗口,该进程将结束。

      咕哝&

    3. 在您的命令周围使用 (&)。这将与 & 一样在后台运行,但是当您关闭终端窗口时,该进程不会被终止。

      (咕噜声)

    【讨论】:

    • 我相信这会解决您的问题,但如果我误解了您的问题,我深表歉意。
    • & 不起作用。但是,打开一个新终端确实有效。某处是否有关于此的文档?你是怎么想到"&"(grunt w &) 的?
    • 很抱歉 & 是基于 *nix 的,不知何故我没有注意到 C:/ 暗示窗口。此链接可以为您指明在 Windows 上复制此行为的正确方向。 tomshardware.com/forum/34598-45-windows-command-background-unix 。如果您在页面的大约一半处查看 start 命令,在我看来它会起作用,但我不确定。
    • 我在 *nix(特别是 Mac)上,所以这对我有用!谢谢。
    【解决方案2】:

    Windows 使用

    start grunt
    

    这将带来一个 CMD 窗口,该窗口将在后台“监视”,并使您正在使用的 git-bash 或 cmd 窗口与您离开时一样。

    换句话说,这将为您在单独的 cmd 窗口中运行任务。

    只是想让人们知道这对 cme​​ts 有效。

    【讨论】:

      【解决方案3】:

      我发现通过同时按 Ctrl 和 c 来停止监视过程更简单。 然后我可以使用命令行然后做一些事情,然后当我准备好返回浏览器时再次运行 grunt watch。

      【讨论】:

        【解决方案4】:

        除了@Nick 提出的仅限终端的解决方案,最好有更好的集成节点解决方案。

        这有一个来自 grunt-contib-watch https://github.com/gruntjs/grunt-contrib-watch/issues/340 和 grung-bg-shell https://github.com/rma4ok/grunt-bg-shell/issues/14 的 WONTFIX。

        建议的替代方案是:

        【讨论】:

          【解决方案5】:

          我使用屏幕,https://www.gnu.org/software/screen/,所以我可以在终端窗口之间切换。

          【讨论】:

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