gulp(二)gulp中文API

2021-07-16 15:19

阅读:414

标签:process   exe   error   tps   arch   shel   base   efi   settime   

gulp.src(‘client/js/**/*.js‘) // 匹配 ‘client/js/somedir/somefile.js‘ 并且将 `base` 解析为 `client/js/`
  .pipe(minify())
  .pipe(gulp.dest(‘build‘));  // 写入 ‘build/somedir/somefile.js‘

gulp.src(‘client/js/**/*.js‘, { base: ‘client‘ })
  .pipe(minify())
  .pipe(gulp.dest(‘build‘));  // 写入 ‘build/js/somedir/somefile.js‘
gulp.src(‘./client/templates/*.jade‘)
  .pipe(jade())
  .pipe(gulp.dest(‘./build/templates‘))
  .pipe(minify())
  .pipe(gulp.dest(‘./build/minified_templates‘));
gulp.task(‘somename‘, function() {
  // 做一些事
});
gulp.task(‘mytask‘, [‘array‘, ‘of‘, ‘task‘, ‘names‘], function() {
  // 做一些事
});

//任务可以异步执行,如果 fn 能做到以下其中一点:

//1.接受一个 callback
// 在 shell 中执行一个命令
var exec = require(‘child_process‘).exec;
gulp.task(‘jekyll‘, function(cb) {
  // 编译 Jekyll
  exec(‘jekyll build‘, function(err) {
    if (err) return cb(err); // 返回 error
    cb(); // 完成 task
  });
});

//2.返回一个 stream
gulp.task(‘somename‘, function() {
  var stream = gulp.src(‘client/**/*.js‘)
    .pipe(minify())
    .pipe(gulp.dest(‘build‘));
  return stream;
});

//返回一个 promise
var Q = require(‘q‘);
gulp.task(‘somename‘, function() {
  var deferred = Q.defer();
  // 执行异步的操作
  setTimeout(function() {
    deferred.resolve();
  }, 1);
  return deferred.promise;
});

 

var watcher = gulp.watch(‘js/**/*.js‘, [‘uglify‘,‘reload‘]);
watcher.on(‘change‘, function(event) {
  console.log(‘File ‘ + event.path + ‘ was ‘ + event.type + ‘, running tasks...‘);
});

gulp.watch(‘js/**/*.js‘, function(event) {
  console.log(‘File ‘ + event.path + ‘ was ‘ + event.type + ‘, running tasks...‘);
});

 

参考:

http://www.ydcss.com/archives/424

https://www.gulpjs.com.cn/docs/api/

gulp(二)gulp中文API

标签:process   exe   error   tps   arch   shel   base   efi   settime   

原文地址:https://www.cnblogs.com/fengyouqi/p/8183514.html


评论


亲,登录后才可以留言!