如何使Grunt捕获npm构建任务错误并失败任务?

时间:2019-11-22 00:31:17

标签: npm gruntjs

您好,我们为项目配置了Gruntfile.js,其中包含以下信息 (出于演示目的,我删除了许多其他不相关的内容)。

// ...

// Define the configuration for all the tasks
grunt.initConfig({

    // Project settings
    project: appConfig,


    concurrent: {
        options: {
            stderr: true,
            stdout: true,
            failOnError: true
        },

        webpackDevImagmin: ['run:webpackDev'],
    },


    run: {
        options: {
            stderr: true,
            stdout: true,
            failOnError: true
        },
        webpackDev: {
            cmd: 'npm',
            args: [
                'run',
                'build:dev'
            ],
            options: {
                stderr: true,
                stdout: true,
                failOnError: true
            }
        }
    },


});

grunt.registerTask('buildInternal:app', [
    'concurrent:webpackDevImagmin',
]);

在我们的项目中,我们故意删除了一些文件,以使npm任务失败。但是当我们执行grunt命令时,我们看到了类似的

  
ERROR in ./app/public/modules/PartnershipsCtrl.js
    Module not found: Error: Cannot resolve module 'our/services/OurResource' in /code/our/app/public/modules/partnerships/controllers
    @ ./app/public/modules/partnerships/controllers/PartnershipsCtrl.js 9:4-53

Done, without errors.

我的理论是npm错误不会为该任务返回false,我的问题是如何使它在错误时返回false并使grunt Task失败?

0 个答案:

没有答案
相关问题