0

I want to concat a couple of js files I have in my src/ directory, like the ones that are needed on every page and for some specific pages that need multiple files. The rest of the files I want to copy with the current directory structure in tact. These are the files that are used only on one page and are the only page specific jsfile for that page.

So I would like to exclude the src and files attributes of the first type of tasks and exclude those in the last task.

How can this be achieved?

JelteF
  • 3,021
  • 2
  • 27
  • 35
  • If you use compression, minification then probably it is more efficient to glue everything into a big file. The downloaded file size won't be much bigger and you spare a few requests at least. If you have client side caching as well then this additional few percent of network usage would be one time only. – Lajos Veres Mar 22 '14 at 22:29

1 Answers1

0

You could use create an array with all the files you mean to concatenate outside task scope. Then you loop through that array to concatenate the javascript files listed in the array in one task like uglify and create another task to copy all the files through another task like copy.

But the magic would happen when you use the same pre-defined array to list the exceptions that are not going to be included in the copy task.

OR you could prefixes like:

uglify: {
    dist: {
        files: {
            'dest/output.min.js': [
                'app/js/**/concatenate-*.js',
            ]
        }
    }
}

copy: {
    dist: {
        src : [
            'app/js/**/*.js',
            // exclude files
            '!app/js/**/concatenate-*.js'
        ]
    }
}

Note that I only added the relevant part within each task, normally the tasks would need more configuration than just that.

Wallace Sidhrée
  • 11,221
  • 6
  • 47
  • 58