【问题标题】:Getting Grunt.js to run node.js module让 Grunt.js 运行 node.js 模块
【发布时间】:2015-10-31 07:34:30
【问题描述】:

我编写了一个 node.js 模块,可以使用“require”从文件运行,也可以从终端运行 node copyright.update()。我对这个功能很满意,它在这两种情况下都有效。我也希望能够从 Gruntfile.js 运行它。

目前我的 grunt 文件如下所示:

module.exports = function(grunt) {

    grunt.initConfig({

        "update-copyright": {
            "run": true
        }
    });

    grunt.task.loadTasks('./runner');
};

而runner目录下的脚本是这样的:

var copyright = require('./update-copyright');

module.exports = function(grunt) {

    grunt.registerMultiTask('update-copyright', 'update copyright headers', function() {
        var done = this.async();
        copyright.update(done);
    });
};

当我运行“grunt update-copright”时,我得到了通常的完成,没有错误,但实际上没有执行任何操作。我确定我错过了一些简单的东西。非常感谢任何帮助!

【问题讨论】:

  • 你的任务是完全同步的吗?
  • 感谢您的浏览。它是完全异步的。是这个问题吗?
  • 感谢@IgorRaush - 修复了它!
  • Grunt 会在你的任务有机会做任何事情之前终止进程。看起来这是个问题:)

标签: javascript node.js gruntjs node-modules


【解决方案1】:

感谢 Igor Raush 的评论,我得到了运行:

var copyright = require('./update-copyright');

module.exports = function(grunt) {

    grunt.registerMultiTask('update-copyright', 'update copyright headers', function() {
        var done = this.async();
        copyright.update(done);
    });
};

【讨论】:

    猜你喜欢
    • 2013-05-04
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 2015-04-20
    • 2018-08-23
    • 2018-09-07
    相关资源
    最近更新 更多