-
-
Save lijie2000/9adfb0b98c3fd7266dfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
del = require('del'), | |
plugins = require('gulp-load-plugins')(), | |
bower = require('main-bower-files'), | |
source = require('vinyl-source-stream'), | |
buffer = require('vinyl-buffer'), | |
browserify = require('browserify'), | |
browserSync = require('browser-sync'); | |
var conf = { | |
build: './build/', | |
src: './src/' | |
}; | |
gulp.task('clean:build', function(next) { | |
return del(conf.build, next); | |
}); | |
gulp.task('html', function(){ | |
return gulp.src(conf.src + 'index.html') | |
.pipe(plugins.size({title: 'html:before'})) | |
.pipe(plugins.htmlmin({collapseWhitespace: true})) | |
.pipe(plugins.size({title: 'html:after'})) | |
.pipe(gulp.dest(conf.build)); | |
}); | |
gulp.task('js:lint', function() { | |
return gulp.src(conf.src + '**/*.js') | |
.pipe(plugins.jshint()) | |
.pipe(plugins.jshint.reporter('default')); | |
}); | |
gulp.task('js:browserify', function() { | |
return browserify(conf.src + 'js/main.js').bundle() | |
.pipe(source('app.min.js')) | |
.pipe(buffer()) | |
.pipe(plugins.size({title: 'js:before'})) | |
.pipe(plugins.uglify()) | |
.pipe(plugins.size({title: 'js:after'})) | |
.pipe(gulp.dest(conf.build)); | |
}); | |
gulp.task('js', ['js:lint', 'js:browserify']); | |
gulp.task('css', function(){ | |
return gulp.src(conf.src + '**/*.css') | |
.pipe(plugins.csslint()) | |
.pipe(plugins.jshint.reporter()) | |
.pipe(plugins.size({title: 'css:before'})) | |
.pipe(plugins.cssmin()) | |
.pipe(plugins.concat('app.min.css')) | |
.pipe(plugins.size({title: 'css:after'})) | |
.pipe(gulp.dest(conf.build)); | |
}); | |
gulp.task('vendors:js', function() { | |
return gulp.src(bower()) | |
.pipe(plugins.filter('**/*.js')) | |
.pipe(plugins.size({title: 'js:vendors:before'})) | |
.pipe(plugins.uglify()) | |
.pipe(plugins.concat('vendors.min.js')) | |
.pipe(plugins.size({title: 'js:vendors:after'})) | |
.pipe(gulp.dest(conf.build)); | |
}); | |
gulp.task('vendors:css', function() { | |
return gulp.src(bower()) | |
.pipe(plugins.filter('**/*.css')) | |
.pipe(plugins.size({title: 'css:vendors:before'})) | |
.pipe(plugins.cssmin()) | |
.pipe(plugins.concat('vendors.min.css')) | |
.pipe(plugins.size({title: 'css:vendors:after'})) | |
.pipe(gulp.dest(conf.build)); | |
}); | |
gulp.task('vendors', ['vendors:js', 'vendors:css']); | |
gulp.task('browser-sync', function() { | |
return browserSync({ | |
server: { | |
baseDir: conf.build, | |
open: false | |
} | |
}); | |
}); | |
gulp.task('build', ['html', 'js', 'css', 'vendors']); | |
gulp.task('serve', ['clean:build'], function() { | |
gulp.start(['build', 'browser-sync']); | |
gulp.watch(conf.src + 'css/**/*.css', ['css', browserSync.reload]); | |
gulp.watch(conf.src + 'js/**/*.js', ['js', browserSync.reload]); | |
gulp.watch(conf.src + 'index.html', ['html', browserSync.reload]); | |
}); | |
gulp.task('default', ['build']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment