Grunt watch Running “watch” task Waiting

白昼怎懂夜的黑 提交于 2019-12-11 02:17:26

问题


I have a problem with grunt-watch. When I use "grunt" in terminal outputs "Running "watch" task Waiting..."

krp-arina@krparina-Lenovo-G555:~/server$ grunt
Running "watch" task
Waiting...
krp-arina@krparina-Lenovo-G555:~/server$ grunt -v
Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.

Registering "grunt-contrib-less" local Npm module tasks.
Reading /home/krp-arina/server/node_modules/grunt-contrib-less/package.json...OK
Parsing /home/krp-arina/server/node_modules/grunt-contrib-less/package.json...OK
Loading "less.js" tasks...OK
+ less

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /home/krp-arina/server/node_modules/grunt-contrib-watch/package.json...OK
Parsing /home/krp-arina/server/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ default, w

No tasks specified, running default tasks.
Running tasks: default

Running "default" task

Running "watch" task
Waiting...
Verifying property watch exists in config...OK

But this does nothing, it just ends.

I want to compile less at each change. Here's my Gruntfile.js

module.exports = function(grunt) {
  require('load-grunt-tasks')(grunt);
  // Project configuration.

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    less: {
      dist:{
        files: {
          'pd_wp/www/wp-content/themes/anarchy/css/commons.css':'pd_wp/www/wp-content/themes/anarchy/css/commons.less'
        },
        options: {
          compress: true,
          cleancss: false
        }
      }
    },
    watch: {
      options: {
        less: {
          files: ['pd_wp/www/wp-content/themes/anarchy/css/*.less'],
          tasks: ['less'],
          // options: {
          //   spawn: false
          // }
        }
      }
    }
  });


  // Default task(s).
  grunt.registerTask('w', ['watch']);
  grunt.registerTask('default', ['watch']);

};

I use grunt-cli v0.1.13 grunt v0.4.5 grunt-contrib-less v1.0.0 grunt-contrib-watch v0.6.1 load-grunt-tasks v3.1.0

nodejs v0.12.1

Somebody tell me what am I doing wrong


回答1:


I'm pretty sure your issue here is the order of your json config. I may be wrong though. The docs list watch: { taskName: { options: {} } }

and you have

watch: { options: { taskName: {} } }

have you tried this:

watch: {
      less: {
          files: ['pd_wp/www/wp-content/themes/anarchy/css/*.less'],
          tasks: ['less']
      }
  }

grunt-contrib-watch docs



来源:https://stackoverflow.com/questions/29371344/grunt-watch-running-watch-task-waiting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!