• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

MeCKodo/gulpfile: 自己项目中的gulp配置

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

MeCKodo/gulpfile

开源软件地址(OpenSource Url):

https://github.com/MeCKodo/gulpfile

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

2016/01/01

  • 本次新增postCSS+sass配置
var gulp = require('gulp'),
    ugjs = require('gulp-uglify'),
    //minicss = require('gulp-minify-css'),
    imagemin = require('gulp-imagemin'),
    clean = require('gulp-clean'),
    replace = require('gulp-replace'),
    rev = require('gulp-rev-append'),
    ifElse = require('gulp-if-else'),
    htmlreplace = require('gulp-html-replace'),
    browserSync = require('browser-sync').create(),
    base64 = require('gulp-base64'),
    runSequence = require('run-sequence'),
    bsReload = browserSync.reload;

var postcss = require('gulp-postcss'); //postcss本身
var autoprefixer = require('autoprefixer');
var precss = require('precss'); //提供像scss一样的语法
var cssnano = require('cssnano');  //更好用的css压缩!
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');

var path = './src/',
    csspath = './src/css/**/*.css',
    sasspath = './src/sass/**/*.scss',
    jspath = './src/js/**/*.js',
    htmlpath = './src/views/**/*.html',
    ifonpath = './src/webfont/**';

var disPath = './Public/',
    disCssPath = './public/css',
    disJsPath = './Public/js',
    disHtmlPath = './Application/Home/View',
    disifonpath = './Public/webfont';

var urlTag = '';
var NODE_ENV = '';

gulp.task('ugjs',function() {
    return gulp.src(jspath)
        .pipe(replace('__target__',urlTag))
        .pipe(replace('../../','../../Public/'))
        .pipe(ifElse(NODE_ENV === 'public',ugjs))
        .pipe(gulp.dest(disJsPath));
});
gulp.task('css',function() {
    var processes = [cssnano];

	gulp.src(csspath)
		.pipe(ifElse(NODE_ENV === 'public',function() {
            return postcss(processes)
        }))
        .pipe(base64({
            extensions: ['png', /\.jpg#datauri$/i],
            maxImageSize: 10*1024 // bytes,
        }))
	.pipe(gulp.dest(disCssPath));
});
gulp.task('sass',function() {
    var processes = [
        autoprefixer({browsers: ['last 2 version', 'safari 5', 'opera 12.1', 'ios 6', 'android 4','> 10%']}),
        precss // background: color($blue blackness(20%));  precss为了用这样的语法
    ];
    return gulp.src(sasspath)
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(postcss(processes))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('./src/css'));
});

gulp.task('images', function () {
    return gulp.src('src/images/**/*.*')
            .pipe(imagemin({
                progressive: true
            }))
            .pipe(gulp.dest('Public/images'));
});

gulp.task('iconfont', function () {
    return gulp.src(ifonpath)
        .pipe(gulp.dest(disifonpath));
});
gulp.task('view',['clean'],function() {
    return gulp.src(htmlpath)
            .pipe(rev())
            .pipe(replace('__target__',urlTag))
            .pipe(replace('..\/..\/','__PUBLIC__/'))
            .pipe(replace('<a href="..\/','<a href="__APP__/'))
            .pipe(htmlreplace({
                js : {
                    src : '',
                    tpl : ''
                }
            }))
            .pipe(gulp.dest(disHtmlPath));
});

gulp.task('clean',function() {
    return gulp.src(disHtmlPath, {read: true})
        .pipe(clean());
});

gulp.task('build',function() {
    NODE_ENV = 'public';
	gulp.start('view','ugjs','sass','css','component','iconfont','images');
});
//gulp.task('auto',function() {
    //gulp.watch([csspath],['css']);
    //gulp.watch([sasspath],['sass']);
    //gulp.watch([jspath],['ugjs']);
    //gulp.watch([htmlpath],['view']);
    //gulp.watch('./src/component/*.html',['component']);
//});

gulp.task('reload',function() {

    browserSync.init(htmlpath,{
        startPath : "/views/",
        server: cpath,
        notify:false
    });
    //gulp.watch([csasspath],['collegesass']);
    gulp.watch([csasspath]).on('change',function() {
        runSequence('collegesass', 'collegecss',function() {
            bsReload();
        });
    });
    gulp.watch([cjspath],['collegejs']).on('change',bsReload);
    gulp.watch([chtmlpath],['collegeview']).on('change',bsReload);

});




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
cake-contrib/Cake.Gulp: A set of aliases for Cake to help with running Gulp scri ...发布时间:2022-06-21
下一篇:
6thSence/Gulp-发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap