Unferth
Unferth

Reputation: 4678

How to configure grunt copy task to exclude .js files from a subdirectory

I am using grunt-contrib-copy to copy folders and files from my src folder to build folder. But I want to exclude all .js files from the app subdirectory in my src directory. This is my Gruntfile. But it is copying all .js files from the subdirectories in app directory instead of excluding. What changes should I make to make it work.

This is my grunt file:

module.exports = function(grunt) {
  grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
    // Task configuration.
concat: {
  dist: {
    src: ['src/app/**/*.js'],
    dest: 'build/app.min.js'
  }
},
    copy: {
    main: {
      files: [
         //includes files within path and its sub-directories
            //{src: ['src/**', '!/src/app/**/*.js'], dest: 'build/', filter: 'isFile'}
        {expand: true, src: ['src/**', '!/src/app/**/*.js'], dest: 'build/', filter: 'isFile'}
      ]
    }
} 
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
 grunt.registerTask('default', ['concat', 'copy']);
};

Reference: Configure grunt copy task to exclude files/folders

Thanks.

Upvotes: 0

Views: 1199

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

Can you try to remove the first slash after the exclamation mark? So change this:

'!/src/app/**/*.js'

to this:

'!src/app/**/*.js'

Upvotes: 1

Related Questions