A gruntjs plugin to autocreate index files that exports nested nodejs modules.

npm install grunt-nested-exports
4 downloads in the last month


A gruntjs plugin to automatically create index files for node modules in nested folder structures.

Getting Started

This plugin requires Grunt ~0.4.1

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-nested-exports --save-dev

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


The "nested_exports" task


In your project's Gruntfile, add a section named nested_exports to the data object passed into grunt.initConfig().

    nested_exports: {
        your_target: {
            // Target-specific file lists go here.

Configuration Options

The plugin supports the following configuration options:

Option Type Default Description
autocodeDelimiter String --autocode-delimiter The delimiter should be added above custom code in manually created index files, as otherwise it would be overridden by the plugins autogenerated code.

Usage Examples

The plugin will scan the given directories for javascript files (except index.js files), detect the included exports statements and require them in an index.js created for each directory.

Running the plugin on the following example structure:

└── lib
    ├── sub
    │   └── SubModule.js
    └── Module.js

Will produce the following index files, where each index file requires all sibling files and directories:

└── lib
    ├── sub
    │   ├── index.js
    │   └── SubModule.js
    ├── index.js
    └── Module.js

If it is required to add custom code to an index file, the autocode delimiter can be used:

exports.sub = require('./sub');
exports.Module = require('./Module').Module;

// --autocode-delimiter
var code = 'All custom code goes here';


Currently, only named exports (e.g. exports.MyModule = function MyModule () {};) will be detected.


Thanks to the wonderful gruntjs project and all the people behind it. Also, this plugin is inspired by an article about writing grunt plugins written by Jacob Gable.

Release History

Release Description
1.0.0 Initial release.
npm loves you