Search code examples
gruntjsgrunt-contrib-concat

Ignore all files in folder grunt concat


I am trying to concatenate all js files in the root and in any other folders of my app, but ignore any files in the node_modules folder. For some reason this setup still takes the node modules, too:

 concat: {
            dist: {
                src: ['*.js', '**/*.js', '!node_modules/*.js'],
                dest: 'concat.js'
            }
        },

Thanks so much


Solution

  • To negate matching the whole node_modules directory use this glob pattern:

    '!node_modules/**/*.js'
    
    1. You probably need to also negate your Gruntfile.js too, in which case you can include multiple ! negation patterns.
    2. Also, as concat.js is being written to the projects root directory, you'll need to negate that too to exclude that on subsequent runs of the task.

    For example:

    concat: {
      dist: {
        src: ['*.js', '**/*.js', '!node_modules/**/*.js', '!Gruntfile.js', '!concat.js'],
        dest: 'concat.js'
      }
    },