Gulp.js 是一个简单、直观的构建系统。崇尚代码优于配置,使复杂的任务更好管理。通过结合 NodeJS 的数据流的能力,你能够快速构建。通过简单的 API 接口,只需几步就能搭建起自己的自动化项目构建工具。
您可能感兴趣的相关文章
下面是一个简单的代码示例:
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']);