Giter VIP home page Giter VIP logo

glup's Issues

gulp环境配置

常用模块演示

目录结构
这里写图片描述
代码如下

var gulp = require('gulp'),
    minifycss = require('gulp-minify-css'),
    //minifyhtml = require('gulp-minify-html'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    //imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    del = require('del'),
    less = require('gulp-less');

gulp.task('less', function () {
    return gulp.src('less/bootstrap.less')
        .pipe(less())
        .pipe(gulp.dest('dist/style'));
});
gulp.task('minify', function() {
    return gulp.src(['js/*.js'])
        .pipe(concat('main.js')) //合并所有js到main.js
        .pipe(rename({
            suffix: '.min'
        })) //rename压缩后的文件名 让main.js变成main.min.js
        .pipe(uglify()) //执行压缩
        .pipe(gulp.dest('./dist/js'))
});
gulp.task('minifycss', function() {
    return gulp.src('./style/*.css') //压缩的文件
        .pipe(concat('main.css')) //合并所有js到main.js
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(minifycss())
        .pipe(gulp.dest('./dist/style')); //输出文件夹
});

gulp.task('imagemin', function() {
    return gulp.src('./images/*.+(jpeg|jpg|png)')
        .pipe(imagemin({
            optimizationLevel: 7, //类型:Number  默认:3  取值范围:0-7(优化等级)
            progressive: true, //类型:Boolean 默认:false 无损压缩jpg图片
            interlaced: true, //类型:Boolean 默认:false 隔行扫描gif进行渲染
            multipass: true //类型:Boolean 默认:false 多次优化svg直到完全优化
        }))
        .pipe(gulp.dest('./dist/images'));
});

gulp.task('default', ['minify', 'minifycss', 'less', 'imagemin']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.