• 构建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

  • 相关阅读:
    直播源列表
    MySQL为什么"错误"选择代价更大的索引
    C#中ConfigureAwait的理解(作者Stephen)
    理解C#中的 async await
    C#中Task.Delay() 和 Thread.Sleep() 区别
    扁平结构数据变成嵌套结构数据(树状结构)
    判断两个数组相同 两个对象相同 js
    嵌套结构数据(树状结构)变成扁平结构不带子元素(children)
    嵌套结构数据(树状结构)变成扁平结构带有子元素(children)
    2022.1.11学习日志
  • 原文地址:https://www.cnblogs.com/dontes/p/9402628.html
Copyright © 2020-2023  润新知