0

In my Gruntfile.js I find myself concatenating lots of glob results. Right now it doesn't seem to affect build time but I wondered is there a more performant way of concatenating multiple arrays.

var pattern = 'lib/module/{products,payments,users}';
var code = {
    project: []
        .concat(glob.sync('lib/editor/*.js'))
        .concat(glob.sync('lib/jasmine/helper/*.js'))
        .concat(glob.sync('lib/task/*.js'))
        .concat([
            'Gruntfile.js',
            'models.js',
            'routes.js',
            'server.js'
        ]),
    backend: []
        .concat(glob.sync(pattern + '/{model}/*.js'))
        .concat(glob.sync(pattern + '/route/*.js')),
    frontend: []
        .concat([
            'lib/application.js'
        ])
        .concat(glob.sync(pattern + '/collection/*.js'))
        .concat(glob.sync(pattern + '/editor/*.js'))
        .concat(glob.sync(pattern + '/router/*.js'))
        .concat(glob.sync(pattern + '/view/*.js')),
    spec: []
        .concat(glob.sync(pattern + '/spec/*.js'))
};
ezraspectre
  • 3,148
  • 5
  • 23
  • 28
  • 1
    this has been asking before and it looks like what you have is the most efficient method. http://stackoverflow.com/questions/5080028/what-is-the-most-efficient-way-to-concatenate-n-arrays-in-javascript – Da Rod Mar 02 '15 at 14:55
  • thanks for the link, didnt find it on my first lookup, the wording is better on the other answer too – ezraspectre Mar 02 '15 at 19:33

0 Answers0