Automate npm and bower install with grunt

前端 未结 5 1678
耶瑟儿~
耶瑟儿~ 2021-01-29 21:38

I have a node / angular project that uses npm for backend dependency management and bower for frontend dependency management. I\'d like to use a grunt task to do both install co

5条回答
  •  别那么骄傲
    2021-01-29 22:11

    You need to tell grunt that you're using an async method (.exec) by calling the this.async() method, getting a callback, and calling that when exec is done.

    This should work:

    module.exports = function(grunt) {
        grunt.registerTask('install', 'install the backend and frontend dependencies', function() {
            var exec = require('child_process').exec;
            var cb = this.async();
            exec('bower install', {cwd: './frontend'}, function(err, stdout, stderr) {
                console.log(stdout);
                cb();
            });
        });
    };
    

    See Why doesn't my asynchronous task complete?

提交回复
热议问题