質問

here is my grunt file, run "grunt nj" or "grunt nu" works fine, " grunt watch -v -d " works too, when file change, terminal shows the file change log, but do not run the task at all. searched a lot ,did not find similar case or solution.

var setting = require('./local').setting
setting.env = 'production'
module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json')
    ,uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
        ,report: ['min']
      }
      ,dist: {
        files: [{
          expand: true
          ,cwd: 'public/js/dev'
          ,src: '*.js'
          ,dest: 'public/js'
        }]
      }
    }
    ,jade: {
      compile: {
        options: {
          data: setting
        }
        ,files: [{
          expand: true
          ,cwd: 'views'
          ,src: '*.jade'
          ,ext: '.html'
          ,dest: 'public'
        }]
      }
    }
    ,watch: {
      js: {
        files: ['public/js/dev/*.js']
        ,task: ['nu']
      }
      ,jade: {
        files: ['views/*.jade', 'views/include/*.jade']
        ,task: ['nj']
      }
    }
  })

  grunt.loadNpmTasks('grunt-contrib-uglify')
  grunt.loadNpmTasks('grunt-contrib-jade')
  grunt.loadNpmTasks('grunt-contrib-watch')
  grunt.loadNpmTasks('grunt-newer')
  grunt.registerTask('nu', ['newer:uglify'])
  grunt.registerTask('nj', ['newer:jade'])
  grunt.registerTask('default', ['newer:uglify', 'newer:jade'])

}
役に立ちましたか?

解決

There is a 's' missing to task:

,watch: {
  js: {
    files: ['public/js/dev/*.js']
    ,tasks: ['nu']
  }
  ,jade: {
    files: ['views/*.jade', 'views/include/*.jade']
    ,tasks: ['nj']
  }
}

http://grunt-tasks.com/grunt-contrib-watch/

他のヒント

Try

watch: {
      js: {
        files: ['public/js/dev/*.js'],
        task: ['newer:uglify']
  }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top