我希望在gulp中包含一个文件,如果它存在,当我编译时,用于开发。目前我有以下内容:
gulp.task('compile:js:development', function() {
return gulp.src([
'src/js/**/*.js',
]).pipe(concat('dist.js'))
.pipe(gulp.dest('compiled/js/'))
});我需要将另一个文件添加到此数组中,但前提是该文件存在。我见过gulp-if,但我不认为它有我想要的功能。
我还想警告开发人员,当在控制台中编译进行开发时,这个文件并不存在。
发布于 2014-08-28 22:47:18
Gulp只是一个节点应用程序,所以您可以在Gulp文件中使用任何节点函数。您可以使用fs.exists()轻松地检查文件的存在
gulp.task('compile:js:development', function() {
var fs = require('fs'),
files = ['src/js/**/*.js'],
extraFile = 'path/to/other/file';
if (fs.existsSync(extraFile)) {
files.push(extraFile);
} else {
console.log('FILE DOES NOT EXIST');
}
return gulp.src(files)
.pipe(concat('dist.js'))
.pipe(gulp.dest('compiled/js/'))
});https://stackoverflow.com/questions/25551668
复制相似问题