Grunt Plugin for Extending Grunt Configuration
JavaScript Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tasks
.gitignore
Gruntfile.js
LICENSE.md
Makefile
README.md
jshint.json
package.json

README.md

grunt-extend-config

Grunt Plugin for Extending Grunt Configuration

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-extend-config --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks("grunt-extend-config");

Purpose

This Grunt extension is NOT a regular Grunt tasks. Instead it extends the Grunt API with a single additional function: grunt.extendConfig(config: Object): void. This function is similar to the standard grunt.initConfig(config: Object): void, but allows you to incrementally establish the underlying grunt.config object. The intention is that this way you can better logically group all your task configurations.

Usage Example

Instead of writing...

//  Gruntfile.js
module.exports = function (grunt) {
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-contrib-less");

    grunt.initConfig({
        uglify: {
            "lib": {
                // [...]
            },
            "app": {
                // [...]
            },
            options: {
                // [...]
            }
        },
        less: {
            "lib": {
                // [...]
            },
            "app": {
                // [...]
            },
            options: {
                // [...]
            }
        }
    });

    grunt.registerTask("default", [ "lib", "app" ]);
    grunt.registerTask("lib", [ "uglify:lib", "less:lib" ]);
    grunt.registerTask("app", [ "uglify:app", "less:app" ]);
};

...you can split the configurations and write...

//  Gruntfile.js
module.exports = function (grunt) {
    grunt.loadNpmTasks("grunt-extend-config");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-contrib-less");

    //  general task configurations
    grunt.initConfig({
        uglify: {
            options: {
                // [...]
            }
        },
        less: {
            options: {
                // [...]
            }
        }
    });
    grunt.registerTask("default", [ "lib", "app" ]);

    //  all configurations for building the libraries
    grunt.extendConfig({
        uglify: {
            "lib": {
                // [...]
            }
        },
        less: {
            "lib": {
                // [...]
            }
        }
    });
    grunt.registerTask("lib", [ "uglify:lib", "less:lib" ]);

    //  all configurations for building the application
    grunt.extendConfig({
        uglify: {
            "app": {
                // [...]
            }
        },
        less: {
            "app": {
                // [...]
            }
        }
    });
    grunt.registerTask("app", [ "uglify:app", "less:app" ]);
};