Skip to content

jrf0110/grunt-named-modules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grunt Named Modules

Allows you to specify aliases for your module paths

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-named-modules --save-dev

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

grunt.loadNpmTasks('grunt-named-modules');

The "namedModules" task

Overview

For now, this task has no options and assumes you're using a package.json file. In your package.json file, add a new directive called namedModules:

{
  "scripts": {
    "postinstall": "grunt namedModules"
  },
  ...
  "namedModules": {
    "utils": "lib/utils.js",
    "errors": "lib/errors.js",
    "middleware": "lib/middleware/index.js",
    "configs": "configs/" // <-- alias a directory
  }
}

The name of the module will be the key, and the full module path is the value. Now, anywhere in your code, you can just require the alias:

var utils   = require('utils');
var errors  = require('errors');
var m       = require('middleware');
var aConf   = require('configs/a');

I would just put a watch on my package.json:

watch: {
  namedModules: {
    files: ['package.json'],
    tasks: ['namedModules'],
    options: {
      spawn: false,
    }
  }
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

1.0.2 - Added directory support 1.0.1 - The initial release!

About

Allows you to specify aliases for your module paths

Resources

License

Stars

Watchers

Forks

Packages

No packages published