Grunt 任务不显示正确的值

Grunt task does not display proper value

我已经创建了一个 grunt 任务。下面是代码。

grunt.initConfig({
  log: {
    foo: [1, 2, 3],
    bar: 'hello world',
    baz: false
  }
});

grunt.registerMultiTask('log', 'Log stuff.', function() {
  grunt.log.writeln(this.target + ': ' + this.data);
});

任务 运行 很好。 PFB 屏幕截图。

this.target 和 this.data 表示“未定义”。为什么它显示未定义。请让我知道我错过了什么。 谢谢

编辑- 在调试 grunt 任务时,我在任务中放置了断点。 this.target 和 this.data 显示无效 属性。

刚刚测试了以下内容并且工作正常:

var grunt = require('grunt');

grunt.initConfig({
  log: {
    foo: [1, 2, 3],
    bar: 'hello world',
    baz: false
  }
});

grunt.registerMultiTask('log', 'Log stuff.', function() {
  grunt.log.writeln(this.target + ': ' + this.data);
});

如图:

建议

  • 使用require('grunt')
  • 确保你有最新的 npm install grunt --save
  • 确保你有最新的 npm install grunt-cli -g

更多信息

这是我的版本号: