I’m working on a couple of different libraries currently that share some common ground: They both are compiled into a single file, and they both have dependencies within themselves (file to file). I’ve explored the idea of using an AMD design (such as with tinyamd), but this doesn’t suit every case.
One of the libraries I’m playing with is quite simple and doesn’t warrant using AMD, but it still needs a nice folder structure and file dependencies. To accommodate these dependencies, I chose to work with a tool by Kyle Simpson called ScanTree.
ScanTree works by reading the annotated dependencies in the source files with something like
// require: module.js. By requiring these files, ScanTree knows that they should be executed before the file they’re read in. Using this system is a very easy way to manage a simple dependency tree within your library without the need for any complex setup.
grunt-scantree-concat concatenates each file from the output of ScanTree using Grunt. The configuration is really simple:
scanDir specify the directory for relative path mapping and file searching respectively. When requiring files in annotations, grunt-scantree-concat will use
baseDir (mapped to ScanTree) to specify the directory that should be considered the ‘base’ for all relative paths.
output is the location of the final output file (with all the found files concatenated inside). Inside the options,
footer default to boolean
recursive tells ScanTree to search the
scanDir recursively, which is usually what you’d want to happen.
grunt-scantree-concat could be used nicely to prep a library for minification and gzip’ing in your Grunt config, or for building a single file from all of those pesky unit tests.