1
2つのタスクを持つgulpファイルを用意しています。これは、一連のファイルに対してまったく同じアクションを実行します。入力ファイルと出力名と出力先は唯一の違いです。 2つのバッチのファイルを処理し、コードを複製しないために同じタスクを使用できる方法はありますか?私はある種の機能のようだと思う。 Iveはパラメータを渡してgoogleで探してみましたが、達成しようとしているものの例を見つけることができます。処理するファイルのGulpパス
var outPutFolder = '../';
//Array of all the JS files to compile for scripts.min.js
var js = [
'js/library/_helpers.js',
'js/library/_form-validation.js',
'js/page/_global.js',
'js/library/_ga_event_tracking.js',
'js/library/_postcode-anywhere.js',
'js/library/_count-down-timer.js',
'js/page/_home-page.js',
'js/page/_main_navigation.js',
'js/page/_myaccount.js',
];
//Array of all the JS files to compile for scripts-external.min.js
var externalJs = [
'js/external/_bootstrap.min.js',
'js/external/_bootstrap-select.js',
'js/external/_bootbox.min.js',
'js/external/_jquery.lazyload.js',
'js/external/_jquery.bxslider.js',
];
//JS Task to check files for errors, compile and then minify
gulp.task('scripts', function() {
return gulp.src(js)
.pipe(eslint())
.pipe(eslint.format())
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest(outPutFolder + 'js'))
.pipe(notify({ title:"scripts.min.js",message: "Successfully Compiled", onLast: true }))
.on('end', function() { gutil.log('scripts.min.js compiled successfully!'); });
});
//JS Task to check files for errors, compile and then minify
gulp.task('scriptsExternal', function() {
return gulp.src(externalJs)
.pipe(eslint())
.pipe(eslint.format())
.pipe(concat('scripts-external.min.js'))
.pipe(gulp.dest(outPutFolder + 'js'))
.pipe(notify({ title: "scripts-external.min.js", message: "Successfully Compiled", onLast: true }))
.on('end', function() { gutil.log('scripts-external.min.js compiled successfully!'); });
});
でタスクを実行し、これを試してみてくださいE私が望んでいたことをxactly、ありがとう! – gvperkins