Grunt手表任务不起作用

时间:2014-08-29 17:36:41

标签: javascript gruntjs npm

我是Grunt的新手,我在使用手表功能方面遇到了麻烦。我只有几个任务,当我直接将它们放入CLI时,这两个任务都可以正常工作。但是,请注意不要。这个Gruntfile有什么问题吗?

module.exports = function(grunt) {

  grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),

    watch: {
        files: '<%= uglify.build.src %>',
        tasks: 'uglify',
    },

    uglify: {
      build: {
        src: ['wp-content/themes/custom/js/live/*.js', 'wp-content/themes/custom/js/waypoints/*.js', 'wp-content/themes/custom/js/*.js'],
        dest: 'wp-content/themes/custom/js/test.js'
      }
    },

    jshint: {
      src: ['Gruntfile.js', 'wp-content/themes/custom/js/*.js'],
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        boss: true,
        eqnull: true,
        browser: true,
        globals: {
          require: true,
          define: true,
          requirejs: true,
          describe: true,
          expect: true,
          it: true
        }
      }
    }
  });

  // Load tasks
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task
  grunt.registerTask('default', 'uglify');

};

1 个答案:

答案 0 :(得分:1)

我发现你没有注册任何手表任务。

只需要查看默认任务,或者在想要观看时创建特定任务。

grunt.registerTask("default", ["express","watch"]);
例如,

grunt.registerTask("watchmeTaskName", "watch");