zoukankan      html  css  js  c++  java
  • 构建gulp执行任务

    // 定义web服务模块,增加浏览器同步浏览
    gulp.task('browser-sync', function() {
        browserSync({
            server: {
                baseDir: '.'
            }
        });
    });
    
    // 创建Compass任务,编译Sass生成雪碧图
    gulp.task('compass', function() {
        gulp.src(path.dev.sass+'/*.scss')
            .pipe(compass({
                config_file: './config.rb',    // 配置文件
                css: path.dev.css,             // 编译路径
                sass: path.dev.sass           // sass路径
                //image: path.dev.image        // 图片路径,用于生成雪碧图
            }))
            .pipe(cssver())                    // CSS文件引用URl加版本号
            .pipe(minifycss())                 // 压缩CSS
            .pipe(gulp.dest(path.dist.css))    // 发布到线上版本
            .pipe(reload({stream: true}));
    });
    
    // 压缩HTML
    gulp.task('html', function() {
        gulp.src(path.dev.html+"/*.html")
            .pipe(rev())                    // html 引用文件添加版本号
            .pipe(gulp.dest(path.dist.html))
            .pipe(reload({stream: true}));
    });
    
    //检查脚本
    gulp.task('lint', function() {
        gulp.src(path.dev.js+'/*.js')
            .pipe(jshint())
            .pipe(jshint.reporter('default'));
    });// 图片压缩
    gulp.task('image', function() {
        gulp.src(path.dev.image+'/*.*')
            .pipe(cache(imagemin()))
            .pipe(reload({stream: true}))
            .pipe(gulp.dest(path.dist.image));
            //.pipe(notify({ message: '图片压缩'}));
    });
    
    // 合并压缩JS文件
    gulp.task('script', function() {
        gulp.src(path.dev.js+'/*.js')
            //.pipe(concat('all.js'))            // 合并
            //.pipe(gulp.dest(path.dist.js))
            //.pipe(rename('all.min.js'))        // 重命名
            .pipe(uglify())                    // 压缩
            .pipe(gulp.dest(path.dist.js))
            //.pipe(notify({ message: 'JS合并压缩' }))
            .pipe(reload({stream: true}));
    });
    
    // 清空文件夹
    gulp.task('clean', function() {
        gulp.src([path.dist.css, path.dist.js, path.dist.image], {read: false})
            .pipe(clean());
    });
    
    // 默认任务
    gulp.task("default", function() {
        gulp.run('browser-sync', 'lint', 'compass', 'script', 'image');
    
        // 检测文件发送变化 - 分开监听为了执行对应的命令
        gulp.watch(path.dev.html+'/*.*', ['html']);
        gulp.watch(path.dev.sass+'/*.scss', ['compass']);
        gulp.watch(path.dev.image+'/**', ['image']);
        gulp.watch(path.dev.js+'/*.js', ['lint', 'script']);
    
    });

    https://www.cnblogs.com/morong/p/4469637.html

  • 相关阅读:
    聪明的质检员 (二分)
    分巧克力(二分)
    产生冠军 HDU
    Legal or Not HDU
    确定比赛名次 HDU
    最短路径问题 HDU
    dijkstra算法为什么不能有负边?
    最短路 HDU
    dijkstra算法 模板
    Floyd算法模板--详解
  • 原文地址:https://www.cnblogs.com/dontes/p/9402628.html
Copyright © 2011-2022 走看看