将Grunt更新用于自定义任务

Chr*_*ler 5 javascript gruntjs grunt-contrib-watch

我正在尝试使用grunt-newer来查看文件夹中的文件,如果有任何更改,则触发自定义任务.

我的Gruntfile.js中有类似的东西:

grunt.initConfig({
   watch: {
      widgets: {
         files: "/somepath/*.js",
         tasks: ['newer:mycustomtask']
      }
   }
});

grunt.registerTask("mycustomtask", ["description of my task"], function() {
  console.log("me has been triggered");
});
Run Code Online (Sandbox Code Playgroud)

每当我运行"grunt watch"时,我都会输出:

Running "watch" task
Waiting...
File "/somepath/WidgetA.js" changed.
Running "newer:mycustomtask" (newer) task
Fatal error: The "newer" prefix is not supported for aliases
Run Code Online (Sandbox Code Playgroud)

我用Google搜索但没有发现任何相关信息.任何人都知道我怎么能实现这个?我现在需要在我的"customtask"中更改了哪些文件

Xav*_*our -1

您只需要为您的任务提供一个配置条目(即使是空的):

grunt.initConfig({

  mycustomtask: {
  },

  watch: {
    widgets: {
      files: "/somepath/*.js",
      tasks: ['newer:mycustomtask']
    }
  }
});
Run Code Online (Sandbox Code Playgroud)