Created
November 28, 2014 17:05
-
-
Save pcalves/0ad5ae78eedec0d04633 to your computer and use it in GitHub Desktop.
Basic gulpfile.js (no autoprefixer)
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
/** | |
* This gulpfile considers the following directory structure: | |
* | |
* . | |
* ├── app PHP framework stuff | |
* ├── bower_components Front-end libraries | |
* ├── node_modules Gulp & Gulp modules | |
* ├── public Production-ready assets | |
* │ ├── css | |
* │ ├── fonts | |
* │ ├── img | |
* │ └── js | |
* ├── resources Development assets | |
* │ ├── images | |
* │ ├── scripts | |
* │ └── scss | |
*/ | |
// Gulp Libraries | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var notify = require('gulp-notify'); | |
var sass = require('gulp-ruby-sass') ; | |
var uglify = require('gulp-uglify'); | |
var concat = require('gulp-concat'); | |
var livereload = require('gulp-livereload'); | |
var watch = require('gulp-watch'); | |
var imagemin = require('gulp-imagemin'); | |
var pngquant = require('imagemin-pngquant'); | |
// Paths | |
var sassDir = './resources/scss'; | |
var targetCSSDir = './public/css'; | |
var JSDir = './resources/scripts'; | |
var targetJSDir = './public/js'; | |
var bowerDir = './bower_components'; | |
var imgDir = './resources/images'; | |
var targetImgDir = './public/img'; | |
// Tasks | |
gulp.task('css', function() { | |
return gulp.src(sassDir + '/style.scss') | |
.pipe( | |
sass({ | |
style: 'compressed', | |
sourcemap: true, | |
loadPath: [ | |
sassDir, | |
bowerDir + '/normalize.css', | |
bowerDir + '/bourbon/dist' | |
] | |
}) | |
) | |
.pipe(gulp.dest(targetCSSDir).on("error", gutil.log)) | |
.pipe(notify('CSS minified.')); | |
}); | |
gulp.task('js', function() { | |
return gulp.src([ | |
bowerDir + '/angular/angular.js', | |
bowerDir + '/angular-route/angular-route.js', | |
JSDir + '/app.js' | |
]) | |
.pipe(concat('script.js').on("error", gutil.log)) | |
.pipe(uglify()) | |
.pipe(gulp.dest(targetJSDir)); | |
}); | |
gulp.task('images', function () { | |
return gulp.src(imgDir + '/**/*') | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
use: [pngquant()] | |
}).on("error", gutil.log)) | |
.pipe(gulp.dest(targetImgDir)) | |
.pipe(notify('Images minified.').on("error", gutil.log)); | |
}); | |
gulp.task('watch', function() { | |
livereload.listen(); | |
gulp.watch(sassDir + '/**/*.scss', ['css']); | |
gulp.watch(JSDir + '/**/*.js', ['js']); | |
gulp.watch(imgDir + '/**/*', ['images']); | |
gulp.watch('./public/**').on('change', livereload.changed); | |
gulp.watch('./app/**').on('change', livereload.changed); | |
}); | |
gulp.task('default', ['css', 'js', 'images', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment