Grunt手表任务不起作用

Grunt watch task not working

本文关键字:不起作用 任务 手表 Grunt      更新时间:2023-09-26

我是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');
};

我看到你没有注册任何监视任务。

只需将您的默认任务置于监视状态,或者在需要监视时创建一个特定任务。

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

例如

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