简体   繁体   English

如何在Gulp中仅源文件(无文件夹)?

[英]How to source files only (no folders) in Gulp?

In my gulpfile I'm injecting some files into appcache manifest like this: 在我的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));

It works, more or less, but also injects folders: 它或多或少地起作用,但是也可以注入文件夹:

# 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

How can I ignore folders themselves, but still include files inside? 如何忽略文件夹本身,但仍在其中包含文件? Googling leads to lots of questions about excluding folders with contents. 谷歌搜索导致有关排除包含内容的文件夹的许多问题。

The options object passed to gulp.src is passed down to node-glob , which supports a nodir option : 传递给gulp.src的options对象将传递给node-glob ,后者支持nodir选项

  • nodir Do not match directories, only files. nodir不匹配目录,仅匹配文件。 (Note: to match only directories, simply put a / at the end of the pattern.) (注意: 匹配目录,只需在模式末尾加一个/即可。)

So to exclude folders you can do this: 因此,要排除文件夹,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM