Search code examples
javascriptgruntjsgrunt-contrib-concat

How can I concatenate all JS files in a folder?


I have a main app folder with many subfolders, each with their own subfolders, etc, which along the way contain .js files.

I want to create a grunt task that concatenates all the .js files anywhere under this main top level folder, which is called src.

Is there anyway to do that?

Right now, I have

            cwd: '.',
            src: [
                'src/**/**/*.js',
                'src/**/**/**/*.js',
                'src/**/**/**/**/*.js',
            ],
            dest: 'dist/app/superapp.js'

but this doesn't account for all possible .js file locations. And if I add a new .js in some folder, I don't want to have to manually update the grunt task.


Solution

  • According to the grunt docs, src/**/*.js is all you need here.

    foo/**/*.js will match all files ending with .js in the foo/ subdirectory and all of its subdirectories.