Last active
August 29, 2015 14:24
-
-
Save ar7n/dc7011689f2e7621cedf to your computer and use it in GitHub Desktop.
Gulpfile
This file contains hidden or 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'), | |
browserSync = require('browser-sync'), | |
mainBowerFiles = require('main-bower-files'), | |
less = require('gulp-less'), | |
filter = require('gulp-filter'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
minifyCss = require('gulp-minify-css'), | |
spritesmith = require('gulp.spritesmith'), | |
del = require('del'), | |
util = require('gulp-util'); | |
var paths = { | |
bower: mainBowerFiles(), | |
src:{ | |
html: ['src/*.*'], | |
js: 'src/js/*.js', | |
css: 'src/styles/main.less', | |
img: 'src/images/**/*', | |
fonts: 'src/fonts/*.*', | |
sprites: 'src/sprites/*.*' | |
}, | |
build:{ | |
html: 'build/', | |
js: 'build/js', | |
css: 'build/css', | |
img: 'build/img/', | |
fonts: 'build/fonts', | |
spritesImg: 'build/img/', | |
spritesCss: 'src/styles/' | |
}, | |
watch:{ | |
html: 'src/*.*', | |
js: 'src/js/*.js', | |
css: 'src/styles/*.less', | |
img: 'src/images/*.*', | |
fonts: 'src/fonts/*.*', | |
sprites: 'src/images/sprites/*.png' | |
} | |
}; | |
gulp.task('build:html', function(){ | |
gulp.src(paths.src.html) | |
.pipe(gulp.dest(paths.build.html)) | |
.pipe(browserSync.reload({stream:true})); | |
}); | |
gulp.task('build:js', function(){ | |
gulp.src(paths.bower.concat([paths.src.js])) | |
.pipe(filter('*.js')) | |
.pipe(concat('main.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.build.js)) | |
.pipe(browserSync.reload({stream:true})); | |
}); | |
gulp.task('build:css', function(){ | |
gulp.src(paths.src.css) | |
.pipe(less()) | |
.pipe(concat('main.css')) | |
.pipe(minifyCss()) | |
.pipe(gulp.dest(paths.build.css)) | |
.pipe(browserSync.reload({stream:true})); | |
}); | |
gulp.task('build:img', function(){ | |
gulp.src(paths.bower.concat([paths.src.img])) | |
.pipe(filter(['*.jpg', '*.png'])) | |
.pipe(gulp.dest(paths.build.img)) | |
.pipe(browserSync.reload({stream:true})); | |
}); | |
gulp.task('build:sprites', function () { | |
var spriteData = gulp.src(paths.src.sprites).pipe(spritesmith({ | |
imgName: 'sprite.png', | |
cssName: 'sprite.less', | |
imgPath: '../img/sprite.png', | |
padding: 5 | |
})); | |
// Pipe image stream through image optimizer and onto disk | |
spriteData.img | |
.pipe(gulp.dest(paths.build.spritesImg)); | |
// Pipe CSS stream through CSS optimizer and onto disk | |
spriteData.css | |
.pipe(gulp.dest(paths.build.spritesCss)); | |
}); | |
gulp.task('build:fonts', function(){ | |
gulp.src(paths.bower.concat([paths.src.fonts])) | |
.pipe(filter(['*.eot', '*.otf', '*.woff', '*.ttf', '*.svg'])) | |
.pipe(gulp.dest(paths.build.fonts)) | |
.pipe(browserSync.reload({stream:true})); | |
}); | |
gulp.task('build', ['build:html', 'build:js','build:sprites', 'build:css', 'build:img', 'build:fonts']); | |
gulp.task('reload', browserSync.reload); | |
gulp.task('clean', function(cb){ | |
del('build/', cb); | |
}); | |
gulp.task('serve', function(){ | |
browserSync({ | |
proxy: 'polarisdesign' | |
}); | |
gulp.watch(paths.watch.html, ['build:html']); | |
gulp.watch(paths.watch.js, ['build:js']); | |
gulp.watch(paths.watch.css, ['build:css']); | |
gulp.watch(paths.watch.img, ['build:img']); | |
gulp.watch(paths.watch.sprites, ['build:sprites']); | |
}); | |
gulp.task('default', ['build', 'serve']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment