【问题标题】:How to source files only (no folders) in Gulp?如何在 Gulp 中仅获取文件(无文件夹)?
【发布时间】:2016-08-26 19:44:10
【问题描述】:

在我的 gulpfile 中,我将一些文件注入到 appcache 清单中,如下所示:

var cachedFiles = gulp.src('**', {read: false, cwd: 'build'});

gulp.src('src/*.appcache', {base: 'src'})
.pipe($.inject(cachedFiles, {
    addRootSlash: false,
    starttag: '# inject',
    endtag: '# endInject',
    transform: function(path) {
        return path;
    }
}))
.pipe(gulp.dest(deployPath));

它或多或少有效,但也注入文件夹:

# inject
index.html
app  # <-- I don't want this
app/20_main.js
app/filters.js
view  # <-- I don't want this
view/style.css

如何忽略文件夹本身,但仍将文件包含在其中?谷歌搜索会导致很多关于排除包含内容的文件夹的问题。

【问题讨论】:

    标签: javascript gulp glob


    【解决方案1】:

    传递给gulp.src的选项对象被向下传递给node-glob,它支持nodir option

    • nodir 不匹配目录,只匹配文件。 (注意:要匹配 目录,只需在模式末尾添加 /。)

    所以要排除文件夹,您可以这样做:

    var cachedFiles = gulp.src('**', {read: false, cwd: 'build', nodir: true});
    

    【讨论】:

      猜你喜欢
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      相关资源
      最近更新 更多