gulp常用依赖

先来看看用到的几个依赖

var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    handlebars = require('gulp-handlebars'),
    wrap = require('gulp-wrap'),
    declare = require('gulp-declare'),
    concat = require('gulp-concat'),
    defineModule = require('gulp-define-module'),
    rename = require('gulp-rename'),
    watch = require('gulp-watch'),
    autoprefixer = require('gulp-autoprefixer'),
    fileinclude = require('gulp-file-include'),
    path = require('path'),
    fs = require('fs');

gulp-uglify

用于压缩文件,主要用于压缩js

gulp.src(['static/js/common/**/*.js','components/common/**/*.js','components/'+dir+'/**/*.js','static/js/'+dir+'/**/*.js'])
                .pipe(concat(dir+'.js'))
                .pipe(uglify())
                .pipe(gulp.dest('../WebRoot/js/pa/'));

上述代码,将数组内的js合并成一个js,并且用uglify()进行压缩,最后dest写入到指定文件目录。

再来看段代码

gulp.src(['components/common/**/*.hbs','components/'+dir+'/**/*.hbs'])
                .pipe(handlebars({
                    handlebars: require('handlebars')
                }))
                .pipe(wrap('Handlebars.template(<%= contents %>)'))
                .pipe(declare({
                    namespace: 'ZGXYClode.templates',
                    noRedeclare: true // Avoid duplicate declarations
                }))
                .pipe(concat(dir+'.js'))
                .pipe(gulp.dest('../WebRoot/js/templates/'));

gulp-handlebars

handlebars是一个模版引擎库, ember.js用它作为前端的模版引擎。
gulp-handlebars编译handlebars文件。

gulp-wrap

可以帮助我们定义使用公共的头部和底部

gulp-declare

安全的声明命名空间,设置属性。

gulp-concat

合并js

gulp-rename

改变管道中的文件名。

gulp-watch

监控文件。当监控的文件有所改变时执行特定的任务。

gulp.task('watch',function(){
    gulp.watch(['components/**/*.html','views/**/*.html','components/**/*.hbs'],['templates']);
    gulp.watch(['static/js/**/*.js','components/**/*.js'],['minify-js']);
});

gulp-autoprefixer

解析CSS文件并且添加浏览器前缀到CSS规则里,使用Can I Use的数据来决定哪些前缀是需要的。

gulp.task('minify-css', function () {
    gulp.src('./static/css/*.css')
        .pipe(watch('static/css/*.css',function(event){
            watchLog(event);
        }))
        .pipe(autoprefixer())
        .pipe(gulp.dest('../WebRoot/css/pa'));
});

gulp-file-include

用于引入公共文件

gulp.src('views/**/*.html')
        .pipe(fileinclude({
            prefix: '@@',
            basepath: '@file'
        }))
        .pipe(gulp.dest('../WebRoot/'));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值