Grunt.task.run () does not work

I am trying to use grunt inside my express application.

I have something like this:

var grunt = require('grunt');
require(process.cwd() + '/gruntfile.js')(grunt);
grunt.task.run('development');

But the task seems like this is not a wokring. (no error is output to the console) But if I run "grunt development" directly in the console, it works fine.

+5
source share
1 answer

grunt.task.runjust adds the task to the queue, so it works as part of an existing task, but not inside an external script. Here is a simple technique that I borrowed from grunt/lib/grunt/cli.js. Beware - this is not part of the official API . Problem Grunt 687 notes the need to use an official API for this feature.

var grunt = require('grunt');
process.chdir(__dirname);
var config = require('./Gruntfile');
config(grunt);
console.log('Minifying...');
grunt.tasks(['cssmin']);
+7
source

All Articles