Skip to content

Instantly share code, notes, and snippets.

@leibnizli
Created January 29, 2015 06:26
Show Gist options
  • Save leibnizli/06499509971547fed903 to your computer and use it in GitHub Desktop.
Save leibnizli/06499509971547fed903 to your computer and use it in GitHub Desktop.
gulp配置示例
// var gulp = require('gulp'),
// gulpLoadPlugins = require('gulp-load-plugins'),
// plugins = gulpLoadPlugins();
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
less = require('gulp-less'),
livereload = require('gulp-livereload'),
watch = require('gulp-watch'),
autoprefix = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css');
var browserSync = require('browser-sync');
gulp.task('js', function() {
return gulp.src('src/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest('build/js'));
});
gulp.task('minify', function () {
gulp.src('js/app.js')
.pipe(uglify())
.pipe(gulp.dest('build'))
});
gulp.task('less', function() {
gulp.src('src/less/*.less')
.pipe(watch('src/less/*.less'))
.pipe(less())
.pipe(gulp.dest('src/css/'))
.pipe(livereload());
});
gulp.task('autoprefixer', function () {
gulp.src('src/css/*.css')
.pipe(less())
.pipe(autoprefix('last 2 version', 'ie 8', 'ie 9'))
.pipe(gulp.dest('build/css'));
});
gulp.task('minify-css', function() {
gulp.src('src/css/style.css')
.pipe(minifyCSS({keepBreaks:true}))
.pipe(gulp.dest('build/css'))
});
// gulp.task('watch', function () {
// gulp.watch('templates/*.tmpl.html', ['build']);
// });
gulp.task('browser-sync', function () {
var files = [
'src/*.html',
'src/css/**/*.css',
'src/imgs/**/*.png',
'src/js/**/*.js'
];
browserSync.init(files, {
server: {
baseDir: './app'
}
});
});
gulp.task('default', function () {
// Your default task
});
{
"devDependencies": {
"browser-sync": "^1.7.2",
"gulp": "~3.5.6",
"gulp-autoprefixer": "^2.0.0",
"gulp-concat": "~2.2.0",
"gulp-jshint": "~1.5.1",
"gulp-less": "^1.3.6",
"gulp-livereload": "^2.1.1",
"gulp-minify-css": "^0.3.11",
"gulp-uglify": "~0.2.1",
"gulp-watch": "^2.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment