grunt-amd-tamer

Tame your AMD modules

npm install grunt-amd-tamer
18 downloads in the last week
44 downloads in the last month

grunt-amd-tamer

Build Status Dependency Status devDependency Status

Tame your AMD modules

Getting Started

This plugin requires Grunt ~0.4.2

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-amd-tamer --save-dev

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

grunt.loadNpmTasks('grunt-amd-tamer');

The "amd_tamer" task

Overview

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

grunt.initConfig({
  amd_tamer: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.separator

Type: String
Default value: grunt.util.linefeed

The separator between files. Usually, you don't need to change this

options.normalizeIndexFile

Type: Boolean
Default value: true

Mimics CommonJS behavior with index.js files. An anonymous module that with index.js as its filename will resolve to its parent folder, e.g. folder/index is folder.

options.base

Type: String
Default value: null

Cuts off the string provided from the module name, e.g. if src/ is provided, src/mymodule will be mymodule

options.doubleQuotes

Type: Boolean
Default value: false

If set to true, generated module names and shims are wrapped in double quotes instead of single quotes.

options.namespace

Type: String
Default value: null

Prepends a namespace to each module name, e.g. if test is set as the namespace, mymodule becomes test/mymodule.

options.processName

Type: Function

Allows to define a function to process module names. Keep in mind, only anonymous module are being processed, not named ones.

options.shims

Type: Object

Similar to RequireJS shims property. Allows to export symbols for non-AMD modules.

options.modules

Type: Object

Allows to manually define module which will be appended to the destination file.

Usage Examples

Default Options

In this example, the default options are used to do get a bunch javascript files and set src/ as a base for all modules.

grunt.initConfig({
  amd_tamer: {
    options: {
      base: 'src/'
    },
    files: {
      'dest/file.js': ['src/**/*.js'],
    },
  }
})

Advanced Options

In this example, the base options is set as well. Also, all anonymous get the test namespace. There are also some shims defined for modules that are not an AMD module.

grunt.initConfig({
  amd_tamer: {
    options: {
      base: 'src/',
      namespace: 'test',
      shim: {
        a: {
          exports: 'a.test'
        },
        b: {
          deps: ['a'],
          exports: 'b'
        }
      }
    },
    files: {
      'dest/file.js': ['src/**/*.js'],
    }
  }
})

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

(Nothing yet)

Bitdeli Badge

npm loves you