gulp 合并、压缩、重命名js文件

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var usemin = require('gulp-usemin');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
var rev = require('gulp-rev');
var del = require('del');

// lint JS,静态检查js语法错误
gulp.task('lint', function(){
    return gulp.src('js/**/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// Concat & Minify JS,合并压缩重命名js
gulp.task('minify', function(){
return gulp.src('js/*.js')
    .pipe(concat('dwz.js'))
    .pipe(gulp.dest('dist'))
    .pipe(rename('dwz.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

// clean,清理输出目录
gulp.task('clean', function(){
    return del('dist/*');
});

rename插件还可以接收一个函数对重命名进行更复杂的控制:

.pipe(rename(function(path){
   path.basename += '.min';
   path.extname = '.js'; 
}))

===
[erq]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.