var gulp = require('gulp'); var jslint = require('gulp-jslint');
// build the main source into the min file gulp.task('default', function () { return gulp.src(['source.js'])
// pass your directives // as an object .pipe(jslint({ // these directives can // be found in the official // JSLint documentation. node: true, evil: true, nomen: true,
// you can also set global // declarations for all source // files like so: global: [], predef: [], // both ways will achieve the // same result; predef will be // given priority because it is // promoted by JSLint
// pass in your prefered // reporter like so: reporter: 'default', // ^ there's no need to tell gulp-jslint // to use the default reporter. If there is // no reporter specified, gulp-jslint will use // its own.
// specify whether or not // to show 'PASS' messages // for built-in reporter errorsOnly: false }))
// error handling: // to handle on error, simply // bind yourself to the error event // of the stream, and use the only // argument as the error object // (error instanceof Error) .on('error', function (error) { console.error(String(error)); }); });
imagemin
imagemin是压缩图片的工具。
1 2 3 4 5 6 7 8 9 10 11 12 13
var gulp = require('gulp'); var imagemin = require('gulp-imagemin'); var pngquant = require('imagemin-pngquant');
var handlebars = require('gulp-handlebars'); var wrap = require('gulp-wrap'); var declare = require('gulp-declare'); var concat = require('gulp-concat');
var usemin = require('gulp-usemin'); var uglify = require('gulp-uglify'); var minifyHtml = require('gulp-minify-html'); var minifyCss = require('gulp-minify-css'); var rev = require('gulp-rev');
var gulp = require('gulp'); var inject = require("gulp-inject");
gulp.task('index', function () { var target = gulp.src('./src/index.html'); // It's not necessary to read the files (will speed up things), we're only after their paths: var sources = gulp.src(['./src/**/*.js', './src/**/*.css'], {read: false});
var gulp = require('gulp'); var jscs = require('gulp-jscs'); var gulpFilter = require('gulp-filter');
gulp.task('default', function () { // create filter instance inside task function var filter = gulpFilter(['*', '!src/vendor']);
return gulp.src('src/*.js') // filter a subset of the files .pipe(filter) // run them through a plugin .pipe(jscs()) // bring back the previously filtered out files (optional) .pipe(filter.restore()) .pipe(gulp.dest('dist')); });
gulp-changed
只允许改变的文件通过管道。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
var gulp = require('gulp'); var changed = require('gulp-changed'); var ngmin = require('gulp-ngmin'); // just as an example
varSRC = 'src/*.js'; varDEST = 'dist';
gulp.task('default', function () { return gulp.src(SRC) .pipe(changed(DEST)) // ngmin will only get the files that // changed since the last time it was run .pipe(ngmin()) .pipe(gulp.dest(DEST)); });
gulp-bower
执行bower安装。
1 2 3 4 5 6 7
var gulp = require('gulp'); var bower = require('gulp-bower');
var declare = require('gulp-declare'); var concat = require('gulp-concat');
gulp.task('models', function() { // Define each model as a property of a namespace according to its filename gulp.src(['client/models/*.js']) .pipe(declare({ namespace: 'MyApp.models', noRedeclare: true// Avoid duplicate declarations })) .pipe(concat('models.js')) // Combine into a single file .pipe(gulp.dest('build/js/')); });