Grunt手表一直在观看无限

时间:2014-12-27 22:50:10

标签: gruntjs grunt-contrib-watch

您好我正在使用Grunt将较少的代码编译为CSS。要查看我是否对我的.less文件进行了更改,请使用:

grunt watch

这样做之后,我正在编辑我的.less文件。但在cmd中没有任何反应我仍然看到他正在看我的.less文件。以下是它的截图:

link:http://i.imgur.com/hT8l18f.png

以下是我使用的代码:

gruntfile.js:

module.exports = function(grunt) {

  grunt.initConfig({
    less: {
      development: {
        options: {
          compress: true,
          yuicompress: true,
          optimization: 2
        },
        files: {
          "css/styles.css": "css/styles.less" // destination file and source file
        }
      }
    },
    watch: {
      styles: {
        files: ['less/styles.less'], // which files to watch
        tasks: ['less'],
        options: {
          nospawn: true
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default', ['less', 'watch']);
};

的package.json:

{
  "name": "Coming_soon_code",
  "version": "0.0.0",
  "description": "van een tut",
  "main": "gruntfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-less": "~1.0.0",
    "grunt-contrib-watch": "~0.6.1"
  }
}

此处还有我的文件夹结构的屏幕截图,以备不时之需:

link:http://i.imgur.com/WWAJZb0.png

1 个答案:

答案 0 :(得分:1)

您似乎正在“观看”'less/styles.less'文件...但根据您的屏幕截图或less任务配置,这不是正确的目录,它位于css目录中。试试吧:

watch: {
  styles: {
    files: ['css/styles.less'], // <-- changed the directory here...
    tasks: ['less'],
    options: {
      nospawn: true
    }
  }
}