grunt-concat-deps

Grunt plugin for concatenating files according to their declarative module definitions.

grunt-concat-deps

Grunt plugin for concatenating files according to their declarative module definitions.

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-concat-deps --save-dev

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

grunt.loadNpmTasks('grunt-concat-deps');

The declarative module definition relies on the YuiDoc synax (http://yui.github.io/yuidoc/syntax/) that makes use of the annotations @module and @requires. It is possible to declare multiple modules in one file. Please note that in this case, dependencies inside of one single file are ignored. Find below an example of two files. #####Module_A.js

/**
 * @module A1
 * @requires B
 */
var A1 = function() {
 
}
 
/**
 * @module A2
 * @requires A1
 */
var A2 = function() {
 
}

#####Module_B.js

/**
 * @module B
 */
var B = function() {
 
}

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

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

Type: String Default value: null

The file to be used as an intro (e.g. license information or beginning of self invoking function).

Type: String Default value: null

The file to be used as an outro (e.g. end of self invoking function).

Type: String Default value: null

The file into which the output should be written.

Type: String Default value: \n

The 'glue string' to be used when concatenating the files.

grunt.initConfig({
  main: {
    options: {
        out:   'out/out.js'
    },
    files:   {
        src:  'src/**/*.js'
    }
})
grunt.initConfig({
  main: {
    options: {
        intro: 'src/intro.js',
        outro: 'src/outro.js',
        out:   'out/out.js',
        joinString: '\n'
    },
    files:   {
        src:  'src/**/*.js'
    }
})

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.

  • 0.2.0 Allowed concatenation of undeclared modules
  • 0.1.0 Core functionality implemented