码迷,mamicode.com
首页 > Web开发 > 详细

Gulp.js - 简单、直观的自动化项目构建工具

时间:2016-04-17 12:58:30      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

 

代码示例:

var gulp = require(‘gulp‘);
 
var coffee = require(‘gulp-coffee‘);
var concat = require(‘gulp-concat‘);
var uglify = require(‘gulp-uglify‘);
var imagemin = require(‘gulp-imagemin‘);
 
var paths = {
  scripts: [‘client/js/**/*.coffee‘, ‘!client/external/**/*.coffee‘],
  images: ‘client/img/**/*‘
};
 
gulp.task(‘scripts‘, function() {
  // Minify and copy all JavaScript (except vendor scripts)
  return gulp.src(paths.scripts)
    .pipe(coffee())
    .pipe(uglify())
    .pipe(concat(‘all.min.js‘))
    .pipe(gulp.dest(‘build/js‘));
});
 
// Copy all static images
gulp.task(‘images‘, function() {
 return gulp.src(paths.images)
    // Pass in options to the task
    .pipe(imagemin({optimizationLevel: 5}))
    .pipe(gulp.dest(‘build/img‘));
});
 
// Rerun the task when a file changes
gulp.task(‘watch‘, function() {
  gulp.watch(paths.scripts, [‘scripts‘]);
  gulp.watch(paths.images, [‘images‘]);
});
 
// The default task (called when you run `gulp` from cli)
gulp.task(‘default‘, [‘scripts‘, ‘images‘, ‘watch‘]);

  

Gulp.js - 简单、直观的自动化项目构建工具

标签:

原文地址:http://www.cnblogs.com/jiuyi/p/5400649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!