Skip to content

Grunt task loader importing all entries from the scripts section of package.json as npmRun:{script-key} tasks.

License

Notifications You must be signed in to change notification settings

justlep/grunt-load-npm-run-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-load-npm-run-tasks Build Status NPM Version

A Grunt task loader importing all entries from the scripts section of package.json as npmRun:{script-key} tasks.

Installation

Add the loader to your project:

$ npm i --save-dev grunt-load-npm-run-tasks

Require the loader inside your Gruntfile.js, like:

module.exports = function (grunt) {

    // ... some tasks definitions etc

    require('grunt-load-npm-run-tasks')(grunt);
};

Example

Say your package.json contains some commands in the scripts section, like

{
  "name": "some-project",
  "scripts": [
    "lint": "eslint --max-warnings 5 path/to/**/*.js",
    "bundle": "rollup -c"
  ],
  ...
}

The grunt-load-npm-run-tasks loader imports those scripts as Grunt tasks npmRun:lint and npmRun:bundle which can then be used like any other task.

Example Gruntfile.js:

module.exports = function (grunt) {

    'use strict';

    grunt.registerTask('default', function() {
        grunt.log.ok('I am just the default task defined in Gruntfile.js.');
    });
    
    grunt.registerTask('prepareBuild', [
        'default',
        'copy:someSources',
        'npmRun:lint',
        'npmRun:bundle'
    ]);

    require('grunt-load-npm-run-tasks')(grunt);
 };

Silent mode

By default, all npmRun:xxx Grunt tasks will execute npm run with the ---silent option in order to prevent irrelevant npm debugging output like

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-appliction@1.0.0 test: \`jest test/\`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-appliction@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
...

You can disable silent mode by adding the {silent: false} option to the task loader initialization in your Gruntfile.js:

require('grunt-load-npm-run-tasks')(grunt, {silent: false});

License

MIT

About

Grunt task loader importing all entries from the scripts section of package.json as npmRun:{script-key} tasks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published