Grunt监听——运行“watch”任务,等待中。

3

我在使用grunt-watch时遇到了问题。当我在终端中使用"grunt"命令时,会输出"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

但这并没有任何作用,它只是结束了。

我希望在每次更改时编译 less。 这是我的 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']);

};

我使用的工具版本如下:

  • 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。请问有哪里做错了吗?


请尝试此链接:https://dev59.com/unrZa4cB1Zd3GeqPxAHL - user3546959
我已经点赞了这个问题,能告诉我你是如何解决它的吗?同时这是我的问题...https://stackoverflow.com/questions/49874258/node-js-running-watch-default-task-waiting?noredirect=1&lq=1 - Yuyang He
2个回答

0
我相信你在这里的问题是你的json配置顺序。虽然我可能错了。文档列出了 watch: { taskName: { options: {} } } 而你有 watch: { options: { taskName: {} } } 你试过这个吗:
watch: {
      less: {
          files: ['pd_wp/www/wp-content/themes/anarchy/css/*.less'],
          tasks: ['less']
      }
  }

grunt-contrib-watch文档



0

你需要指定一个任务,例如:

grunt postcss

如果不确定,请输入 grunt -help 命令:

grunt -help
Grunt: The JavaScript Task Runner (v0.4.5)

Usage
 grunt [options] [task [task ...]]

Options
    --help, -h  Display this help text.                                        
        --base  Specify an alternate base path. By default, all file paths are 
                relative to the Gruntfile. (grunt.file.setBase) *              
    --no-color  Disable colored output.                                        
   --gruntfile  Specify an alternate Gruntfile. By default, grunt looks in the 
                current or parent directories for the nearest Gruntfile.js or  
                Gruntfile.coffee file.                                         
   --debug, -d  Enable debugging mode for tasks that support it.               
       --stack  Print a stack trace when exiting with a warning or fatal error.
   --force, -f  A way to force your way past warnings. Want a suggestion? Don't
                use this option, fix your code.                                
       --tasks  Additional directory paths to scan for task and "extra" files. 
                (grunt.loadTasks) *                                            
         --npm  Npm-installed grunt plugins to scan for task and "extra" files.
                (grunt.loadNpmTasks) *                                         
    --no-write  Disable writing files (dry run).                               
 --verbose, -v  Verbose mode. A lot more information output.                   
 --version, -V  Print the grunt version. Combine with --verbose for more info. 
  --completion  Output shell auto-completion rules. See the grunt-cli          
                documentation for more information.                            

Options marked with * have methods exposed via the grunt API and should instead
be specified inside the Gruntfile wherever possible.

Available tasks
          sass  Compile Sass to CSS *                                          
       postcss  Process CSS files. *                                           
         watch  Run predefined tasks whenever watched files change.            
       default  Alias for "watch" task.                                        

Tasks run in the order specified. Arguments may be passed to tasks that accept
them by using colons, like "lint:files". Tasks marked with * are "multi tasks"
and will iterate over all sub-targets if no argument is specified.

The list of available tasks may change based on tasks directories or grunt
plugins specified in the Gruntfile or via command-line options.

For more information, see http://gruntjs.com/

这是 postcss 的运行示例

francoisgravel@LMSD-FGRAVEL vistage-mv3 % grunt postcss
Running "postcss:dist" (postcss) task
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
>> 1 processed stylesheet created.

Done, without errors.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接