首页 > 代码库 > gulp

gulp

 基于流的自动化构建工具

//项目目录下执行
npm install gulp

//安装依赖
gulp combo.js

//压缩文件
npm run build

  

 

 

 

//package.json文件
{
  "name": "myname",
  "version": "1.0",
  "description": "",
  "main": "index.js",
  "scripts":
  {"build": "gulp combojs && gulp combocss"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-alias-combo": "^0.3.0",
    "gulp-concat": "^2.6.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-ng-annotate": "^2.0.0",
    "gulp-ngmin": "^0.3.0",
    "gulp-notify": "^2.2.0",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^1.5.4"
  }
}

  

//gulpfile.js文件

var gulp = require(‘gulp‘);
var uglify = require(‘gulp-uglify‘);//js压缩
var concat = require(‘gulp-concat‘);//文件合并
var rename = require(‘gulp-rename‘);//文件更名
var notify = require(‘gulp-notify‘);//提示信息
var cssmin = require(‘gulp-minify-css‘); //压缩css

gulp.task(‘combojs‘, function () {
    return gulp.src([
        ‘./angular/angular.js‘,
        ‘./jquery/jquery.js‘,
        ‘./js/bootstrap.js‘,
        ‘./js/bootstrap-switch.js‘,
        ‘./toastr/toastr.js‘,
        ‘./js/ui-bootstrap-tpls.min.js‘,
        ‘./js/tm.pagination.js‘,
        ‘./js/app.js‘,
        ‘./js/post.js‘

    ])
        .pipe(concat(‘all.js‘))
        .pipe(gulp.dest(‘./src/js‘))
        .pipe(rename({suffix: ‘.min‘}))
        .pipe(uglify())
        .pipe(gulp.dest(‘./src/js‘));
});

gulp.task(‘combocss‘, function () {
    return gulp.src([
        ‘./css/bootstrap.css‘,
        ‘./css/bootstrap3/bootstrap-switch.css‘,
        ‘./css/fontello.css‘,
        ‘./toastr/toastr.css‘,
        ‘./css/app.css‘
    ])
        .pipe(concat(‘all.css‘))
        .pipe(gulp.dest(‘./src/css‘))
        .pipe(rename({suffix: ‘.min‘}))
        .pipe(cssmin())
        .pipe(gulp.dest(‘./src/css‘));
});

gulp.task(‘default‘, [‘combocss‘, ‘combojs‘], function () {
    console.log(‘gulp完成!‘);
});

  

gulp