返回列表

Gulp自定义插件示例

默认分类 2016/08/08 01:38

示例代码如下:

'use strict';
var through2 = require('through2');
var gulp = require('gulp');
var uglify = require('gulp-uglify');

gulp.task('default', function () {
    gulp.src('./1.js')  
        .pipe(uglify()) //调用插件
        .pipe(through2.obj(function (file, encoding, next) {
            //do something
            file.contents = new Buffer(String(file.contents) + 'var b = 345;'); //改变内容

            next(null, file);
        }))
        .pipe(gulp.dest('./2')); //输出
});