Gulp giving error on symlinks in gulp.src()
Asked Answered
P

3

7

I have a symlink in my images folder that points to another folder containing external images provided by a third party library (managed by bower - gotta love javascript). As part of my build process, I compress all images as follows:

gulp.task('images', function() {
return gulp.src('static/img/**/*')
    .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
    .pipe(gulp.dest('dist/img'))
});

When gulp gets to the symbolic link folder in the img folder, it returns

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: EISDIR, read

Using gulp-debug shows that it baulks on the symlink folder. I am on Mac OSX and the symlink was created using ln -s. Any ideas?

Polypody answered 22/1, 2015 at 0:23 Comment(3)
Have you tried using the actual file / folder instead of the symlink? Just to verify that symlinks are indead the problem. The EISDIR error makes me think that gulp is trying to use a directory as it's src instead of the files in that directory.Bangor
Works fine when it is a folder. I've used this as a temporary solution.Polypody
I am encountering the same issue presently working with JSPM local links...Jeannettajeannette
S
7

gulp.src() uses node-glob, which doesn't crawl symlinks:

** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

Note that symlinked directories are not crawled as part of a **, though their contents may match against subsequent portions of the pattern. This prevents infinite loops and duplicates and the like.

I don't know if it's supposed to error or just skip them.

Saltwort answered 23/1, 2015 at 17:54 Comment(0)
E
4

I was having the same problem when pointing to a symlink folder. The solution was simple, just used vinyl-fs package.

var vfs = require('vinyl-fs');

gulp.task('myTask', [], function() {
  vfs.src('static/img/**/*')
  .pipe(vfs.dest('dist/img'))
)};
Emmerie answered 12/2, 2016 at 21:53 Comment(0)
D
2

You can use the option 'follow: true' to make Gulp follow symlinks. For example:

gulp.src('static/img/**/*', { follow: true })
Deceive answered 24/5, 2016 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.