zoukankan      html  css  js  c++  java
  • gulp(二)gulp中文API

    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/

    工欲善其事 必先利其器
  • 相关阅读:
    前端常用设计模式和工作中应用场景思考
    webpack从零开始打造react项目(更新中...)
    操作系统-进程
    go语言web框架-如何使用gin教程+react实现web项目
    JavaScript逗号运算符的用法
    react的生命周期和使用
    在Vue项目中使用wangEditor
    TypeScript实现axios
    SpringBoot整合邮件发送(thymeleaf和freemarker)
    SpringBoot整合RabbitMQ
  • 原文地址:https://www.cnblogs.com/fengyouqi/p/8183514.html
Copyright © 2011-2022 走看看