I have written so far 11 grunt plugins and some of them are pretty useful, like grunt-nice-package that verifies Nodejs package.json. Today a few of my projects use gulp, and I would like to reuse the same logic to verify the package.json file when running gulp. Here is how to run a grunt task from gulp.
- You will need to install global grunt task runner
npm install -g grunt-cli
- Install gulp-grunt in your project
npm install --save-dev gulp-grunt
- Write a simple gruntfile.js (the name must be
gruntfile.js
currently). Here is mine
1 | module.exports = function (grunt) { |
- Load grunt tasks from the gulp file
1 | var isVerbose = process.argv.some(function (arg) { |
The gulp-grunt
module automatically prefixes all grunt tasks with grunt-
prefix. Thus the registered
nice-package
task will be available from gulp under the name grunt-nice-package
.
- Run the desired grunt tasks
gulp grunt-nice-package
- Add the grunt task to the default task if necessary
gulp.task('default', ['grunt-nice-package', ...]);
That is it!
Note The gulp task does not wait for the asynchronous grunt task to finish, thus it will report that the gulp task has finished, while the grunt task actually is still running.