Search code examples
gruntjsgrunt-contrib-uglify

Grunt fails because of containing ".js" in source's folder name


I have a problem with using grunt. I've configured the uglify task like this:

uglify: {
    my_targets: {
        files: [{
            expand: true,
            cwd: 'build/dev/Assets/JavaScript',
            src: '**/*.js',
            dest: 'build/dist/Assets/JavaScript'
        }]
    }
}

Basically this is working perfect... until it reaches this folder: vendor/conditioner.js/ conditioner.js

Grunt thinks that vendor/conditioner.js is a file (because it matches my src pattern) and tries to load the file, which of course ends in this error:

{ [Error: Unable to read "build/dev/Assets/JavaScript/vendor/conditioner.js" file (Error code: EISDIR).]
  origError: { [Error: EISDIR: illegal operation on a directory, read] errno: -4068, code: 'EISDIR', syscall: 'read' } }

I have no clue, how to tell grunt to ignore the folder (which ends with ".js") and hope you can help. Thanks in advance.


Solution

  • There is no need to write a custom filter. In the documentation for the files object, it is specified that a filter can be a "valid fs.Stats method name". The isFile method already exists. We just need to set the name of this filter in our files object:

    files: [{
        expand: true,
        cwd: 'build/dev/Assets/JavaScript',
        src: '**/*.js',
        dest: 'build/dist/Assets/JavaScript',
        filter: 'isFile'
    }]