build script for big js package

I am writing a quite complex js charting library using d3.js. The code is organise in multiple files (17 to be exact) and each file has one or more classes. Moreover, the code has multiple external dependencies such as d3.js, jQuery, underscore,...

To load the charts, it is necessary to load the different files in an appropriate order to manage the dependencies of the files relatively to each other.

I would like to create a build script that would manage all the dependencies (internal and external) to create a standalone library. I know requirejs, love it and would like to use it. But I did not find a way to make it compile server-side the code without adding a dependency on the client side.

The goal here is really to allow the library to be easily used on any project as any other library by only loading one file. As I plan to use the library on the server side too, I would like the solution to be compatible with node.js too.

Here is a bogus code example that show what my code looks like.

//  in file1.js
var Foo = {}
Foo.Class1 = function(params){
    this.params = params;
    this.bar = function(){
        return this.params.bar || "bar";
    }
}

//  in file2.js
foo.Class2() = function(params){
   $.extend(this, new Foo.Class1(params));

   this.bar = function(){
        return this.params.bar || "BAR";
    }
}

There are lot of projects to combine JavaScripts, for example YUI Compressor, Grunt or Brunch.

I have chosen to go with Grunt. No real reasons except that it looks that it is well documented and very active.

So less than 15 minutes after knowing the existence of Grunt, here is a grunt.js file that resolve my problem.

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
      concat: {
        dist: {
          src: ['file1.js', 'file2.js'],
          dest: 'built.js'
        }
      }
    });
};

Really looking forward to use more Grunt!

cheers Andreas Köberle!