grunt watch task block the command line

收藏待读

grunt watch task block the command line

I’m new to grunt, still learning, so I came up to a very strange problem. When I run "watch" task, my command line becomes blocked, so basically I cant do anything on it. Bare in mind that the task is completed with success. This is my command line output:

C:servercss-test>grunt w
Running "watch" task
Waiting...OK
>> File "compass-examples-master2sassscreen.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...

As you can see, all I do is run "compass" task, it completes successfully.

Insertion point keeps blinking on after the Waiting... text part, but keyboard input doesn’t work.

My grunt configuration

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

};

Problem courtesy of: Ivan V.

Solution

I havn’t used grunt watch, however I believe the problem is that it is a continuously running process, and by default your command line will typically run one process at a time. There are 3 solutions you can use.

  1. Open a new terminal. You can have multiple open at once, and this will allow you to use the second as your main terminal while grunt watch occupies the other.
  2. Use the & symbol in your command. This will begin the process and immediately return the command line to you, allowing you to use it for other things. You can think of it as running the command in the background. The process is still connected to the terminal window, so if you close the window, the process will end.

    grunt w &

  3. Use ( &) around your command. This will run in the background the same as just &, however the process will not be killed when you close the terminal window.

    (grunt w &)
    

Solution courtesy of: Nick Mitchinson

Discussion

Besides terminal only solutions proposed by @Nick, it would good to have better integrated Node solutions.

This had a WONTFIX from grunt-contib-watch https://github.com/gruntjs/grunt-contrib-watch/issues/340 and grung-bg-shell https://github.com/rma4ok/grunt-bg-shell/issues/14 .

Suggested alternatives were:

Discussion courtesy of: Ciro Santilli 709大抓捕 六四事件 法輪功

I find it simpler to just stop the watch process by pressing Ctrl and c at the same time. Then I can use the command line then to do stuff then run grunt watch again when Im ready to go back to the browser.

Discussion courtesy of: jojojohn

I use screen, https://www.gnu.org/software/screen/ , so I can switch between terminal windows.

Discussion courtesy of: Ian Jamieson

For Windows use

start grunt

This will bring a CMD window that will “watch” in the background and leave the git-bash or cmd window you were working in the same as you left it.

In other words, this will run the task in a separate cmd window for you.

Just wanted to let people know this worked per the comments.

Discussion courtesy of: Christian Matthew

This recipe can be found in it’s original form on Stack Over Flow .

原文 : Node.js Recipes

相關閱讀

免责声明:本文内容来源于Node.js Recipes,已注明原文出处和链接,文章观点不代表立场,如若侵犯到您的权益,或涉不实谣言,敬请向我们提出检举。