首页 > 多个项目如何公用一个gulpfile.js

多个项目如何公用一个gulpfile.js

场景:我现在有好几个项目,由于每个项目的目录结构都一样,不想在每个项目里面都去维护一份,想使用一个公用的gulpfile.js,每个项目里面只需要写些必要的配置就好了。


推荐这个 wrench, https://github.com/ryanmcgrath/wrench-js

用该 wrench.readdirSyncRecursive 读取文件,动态require进去,读取各个子项目配置或gulp task,然后根据自己的需求去执行任务,可以参考下面的例子

'use strict';

var gulp = require('gulp');
var wrench = require('wrench');

wrench.readdirSyncRecursive('./gulp').filter(function(file) {
  return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
  require('./gulp/' + file);
});

gulp.task('default', ['clean'], function () {
  gulp.start('build');
});

关于更多gulp内容,你可以参考我们team的总结 https://github.com/Platform-CUF/use-gulp

【热门文章】
【热门文章】