Gulp 在 gulp.src() 中给出符号链接错误

Gulp giving error on symlinks in gulp.src()

我的图像文件夹中有一个 symlink,它指向另一个包含第三方库提供的外部图像的文件夹(由 bower 管理 - 非常喜欢 javascript)。作为构建过程的一部分,我按如下方式压缩所有图像:

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

当 gulp 到达 img 文件夹中的符号 link 文件夹时,它 returns

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

使用 gulp-debug 表明它在 symlink 文件夹上受阻。我在 Mac OSX 上并且 symlink 是使用 ln -s 创建的。有什么想法吗?

gulp.src() 使用 node-glob,不抓取符号链接:

** 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.

我不知道它是应该出错还是跳过它们。

我在指向 symlink 文件夹时遇到了同样的问题。 解决方案很简单,只用了 vinyl-fs 包。

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

gulp.task('myTask', [], function() {
  vfs.src('static/img/**/*')
  .pipe(vfs.dest('dist/img'))
)};

您可以使用选项 'follow: true' 使 Gulp 遵循符号链接。例如:

gulp.src('static/img/**/*', { follow: true })