Search code examples
javascriptconcatenationgruntjscodekitgrunt-contrib-concat

Grunt concat: Use file instructions a la Codekit


I'm trying to convert a CodeKit project to use Grunt (so we can support our Windows friends).

In CodeKit, you can concatenate JS files by including concat instructions as comments in the files you want concatenated. For example, to prepend jquery.validate.js to your scripts.js file, you would add the following comment to scripts.js:

 /* @codekit-prepend "jquery.validate.js" */

How can I configure grunt-concat (or a similar plugin) to concatenate JS files based on instructions within the files themselves? I'd prefer to have concat instructions in the files so it's more clear what's going on (as opposed to referring to Gruntfile.js).


Solution

  • I do not know about codekit syntax, but if all you need is the prepend feature, then take a look at https://github.com/miensol/grunt-concat-in-order, and specifically the filebased approach. You could customize the syntax to extract your codekit prepend syntax or replace that to something like @depend used in the example.

    (for a cross platform example check out my fork, it has a windows safe example, using path.normalize)