在我的gulp.js文件中,我将所有HTML文件从该examples文件夹传输到该build文件夹中.
创建gulp任务并不困难:
var gulp = require('gulp');
gulp.task('examples', function() {
return gulp.src('./examples/*.html')
.pipe(gulp.dest('./build'));
});
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何检索任务中找到(和处理)的文件名,或者我找不到合适的插件.
Ove*_*ous 168
我不确定你想如何使用文件名,但其中一个应该有帮助:
如果您只想查看名称,可以使用类似的内容gulp-debug,其中列出了乙烯基文件的详细信息.将其插入您想要列表的任何位置,如下所示:
var gulp = require('gulp'),
debug = require('gulp-debug');
gulp.task('examples', function() {
return gulp.src('./examples/*.html')
.pipe(debug())
.pipe(gulp.dest('./build'));
});
Run Code Online (Sandbox Code Playgroud)另一种选择是gulp-filelog,我没有使用,但听起来相似(它可能会更清洁).
另一个选项是gulp-filesize输出文件和它的大小.
如果你想要更多的控制,你可以使用类似的东西gulp-tap,它允许你提供自己的功能,并查看管道中的文件.
Vik*_*ram 21
我发现这个插件正在做我期待的事情:gulp-using
简单用法示例:使用.jsx扩展名搜索项目中的所有文件
gulp.task('reactify', function(){
gulp.src(['../**/*.jsx'])
.pipe(using({}));
....
});
Run Code Online (Sandbox Code Playgroud)
输出:
[gulp] Using gulpfile /app/build/gulpfile.js
[gulp] Starting 'reactify'...
[gulp] Finished 'reactify' after 2.92 ms
[gulp] Using file /app/staging/web/content/view/logon.jsx
[gulp] Using file /app/staging/web/content/view/components/rauth.jsx
Run Code Online (Sandbox Code Playgroud)
Nic*_*ick 10
这是另一种简单的方法.
var es, log, logFile;
es = require('event-stream');
log = require('gulp-util').log;
logFile = function(es) {
return es.map(function(file, cb) {
log(file.path);
return cb();
});
};
gulp.task("do", function() {
return gulp.src('./examples/*.html')
.pipe(logFile(es))
.pipe(gulp.dest('./build'));
});
Run Code Online (Sandbox Code Playgroud)
您可以使用gulp-filenames模块来获取路径数组.您甚至可以按名称空间对它们进行分组:
var filenames = require("gulp-filenames");
gulp.src("./src/*.coffee")
.pipe(filenames("coffeescript"))
.pipe(gulp.dest("./dist"));
gulp.src("./src/*.js")
.pipe(filenames("javascript"))
.pipe(gulp.dest("./dist"));
filenames.get("coffeescript") // ["a.coffee","b.coffee"]
// Do Something With it
Run Code Online (Sandbox Code Playgroud)