gulp插件(6) - gulp-rename(文件更名)

功能描述

修改文件名,例如将demo.css修改为demo.min.css,一般配合gulp-minify-css/gulp-uglify压缩插件一起使用


插件安装

$ cnpm install gulp-rename --save-dev

使用方法

例1:与插件gulp-clean-css(不会用?请参考)组合使用,实现对CSS文件压缩后更名为 xxx.min.css

var gulp        = require('gulp'),
    minifyCss   = require('gulp-minify-css'),
    rename      = require('gulp-rename'),
    pump        = require('pump');

gulp.task('testRenameCss', function(cb) {
    pump([
        gulp.src('src/css/*.css'),
        rename({suffix: '.min'})
        minifyCss({
            keepSpecialComments: '*'
        }),
        gulp.dest('dist/css')
    ])
});

例2:与插件gulp-uglify(不会用?请参考)组合使用,实现对JS文件压缩后更名为 xxx.min.js

var gulp       = require('gulp'),
    minifyCss  = require('gulp-uglify'),
    rename     = require('gulp-rename'),
    pump       = require('pump');

gulp.task('testRenameJs', function(cb) {
    pump([
        gulp.src('src/js/*.js'),
        rename({suffix: '.min'}),
        uglify(),
        gulp.dest('dist/js')
    ])
});

你可能感兴趣的:(教程,-,前端自动化工具Gulp,gulp,rename,clean-css,uglify)