Gruntjs 在Grunt检查依赖项安装Grunt任务模块后重新加载/加载Grunt任务

Gruntjs 在Grunt检查依赖项安装Grunt任务模块后重新加载/加载Grunt任务,gruntjs,Gruntjs,在运行进一步的grunt任务之前,我一直在尝试使用grunt检查依赖项来检查NPM模块依赖项。问题是,当缺少的NPM依赖项之一是Grunt任务(例如Grunt contrib concat)时,这没有帮助 由于Grunt显然是在运行“checkDependencies”任务之前注册任务,即使“checkDependencies”将成功安装任何缺失的Grunt任务模块,但这样做太晚了-Grunt已经确定缺失的模块缺失,因此Grunt构建运行失败 一种可行的方法是始终使用命令行,例如npm inst

在运行进一步的grunt任务之前,我一直在尝试使用grunt检查依赖项来检查NPM模块依赖项。问题是,当缺少的NPM依赖项之一是Grunt任务(例如Grunt contrib concat)时,这没有帮助

由于Grunt显然是在运行“checkDependencies”任务之前注册任务,即使“checkDependencies”将成功安装任何缺失的Grunt任务模块,但这样做太晚了-Grunt已经确定缺失的模块缺失,因此Grunt构建运行失败

一种可行的方法是始终使用命令行,例如npm install;咕噜…,但我想我会看看是否有人有一个完全“咕噜内部”的解决方案

下面是一个示例Grunt输出,演示了这个问题

% rm -rf node_modules/grunt-contrib-concat ; grunt

>> Local Npm module "grunt-contrib-concat" not found. Is it installed?

Running "checkDependencies:this" (checkDependencies) task
>> grunt-contrib-concat: not installed!
Invoking npm install...
npm http GET https://registry.npmjs.org/grunt-contrib-concat
npm http 304 https://registry.npmjs.org/grunt-contrib-concat
grunt-contrib-concat@0.3.0 node_modules/grunt-contrib-concat
Warning: Task "concat:dev" not found. Use --force to continue.

Aborted due to warnings.
下面是导致上述输出/错误的gruntfile.js示例:

module.exports = function(grunt) {
    'use strict';

    var config = {
        concat: {
            dev: {
                src: ['foo1.js', 'foo2.js'],
                dest: 'foo_concat.js'
            }
        },
        checkDependencies: {
            this: {
                options: {
                    npmInstall: true
                },
            },
        }
    };

    // trying to make sure all npm nodules listed in package.json are 
    // installed before other grunt tasks
    grunt.loadNpmTasks('grunt-check-dependencies');
    grunt.task.run('checkDependencies');

    // load grunt tasks
    require('load-grunt-tasks')(grunt);

    // alternate approach to loading tasks; exhibits same problem
    // grunt.loadNpmTasks('grunt-contrib-concat');

    grunt.initConfig(config);

    grunt.registerTask('default', ['concat:dev']);
}