15

我是 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');

};
4

5 回答 5

21

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

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

    咕噜声

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

    (咕噜声)

于 2013-03-22T19:15:51.817 回答
6

对于 Windows 使用

start grunt

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

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

只是想让人们知道这在评论中有效。

于 2014-02-16T01:23:56.527 回答
4

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

于 2015-01-23T12:44:11.700 回答
1

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

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

建议的替代方案是:

于 2014-06-15T20:24:18.573 回答
0

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

于 2015-10-27T11:25:32.590 回答