gulp学习

2016-03-14  本文已影响65人  北漂老莫

Gulp API主要包括4个顶级函数。如下

var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    less = require('gulp-less');

// use 'default' so `gulp` to run task
gulp.task('default', ['watch']);
// Error: Cannot find module 'jshint/src/cli'
//     at Function.Module._resolveFilename (module.js:336:15)
//     at Function.Module._load (module.js:278:25)
//     at Module.require (module.js:365:17)
//  need to install jshint as well

// use `gulp jshint` to run task
gulp.task('jshint', function() {
    return gulp.src('source/javascript/**/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(gulp.dest('build'));
})

gulp.task('less', function() {
    return gulp.src('source/less/*.less')
        .pipe(less())
        .pipe(gulp.dest('source/css'))
})

// need to write task before watch task
gulp.task('watch', function() {
    gulp.watch('source/javascript/**/*.js', ['jshint']);
    gulp.watch('source/less/**/*.less', ['less']);
})

上一篇下一篇

猜你喜欢

热点阅读