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']);
user69173
source
share