Last active
July 6, 2016 20:10
-
-
Save rouzbeh84/d7fd383c3cd05e1c2d1e43670839f043 to your computer and use it in GitHub Desktop.
gulpfile.js
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'); | |
var sass = require('gulp-sass'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var browserSync = require('browser-sync'); | |
var useref = require('gulp-useref'); | |
var uglify = require('gulp-uglify'); | |
var gulpIf = require('gulp-if'); | |
var cssnano = require('gulp-cssnano'); | |
var imagemin = require('gulp-imagemin'); | |
var cache = require('gulp-cache'); | |
var del = require('del'); | |
var runSequence = require('run-sequence'); | |
// Development Tasks | |
// ----------------- | |
// Start browserSync server | |
gulp.task('browserSync', function() { | |
browserSync.init({ | |
server: { | |
baseDir: 'dist' | |
}, | |
}) | |
}); | |
// Env Variables | |
// -------------- | |
// source and distribution folder | |
var | |
source = 'app/', | |
dest = 'dist/'; | |
// Bootstrap scss source | |
var bootstrapSass = { | |
in: './node_modules/bootstrap-sass/' | |
}; | |
// Bootstrap fonts source | |
var fonts = { | |
in: [source + 'fonts/*.*', bootstrapSass.in + 'assets/fonts/**/*'], | |
out: dest + 'fonts/' | |
}; | |
// Our scss source folder: .scss files | |
var scss = { | |
in: source + 'scss/styles.scss', | |
out: dest + 'css/', | |
watch: source + 'scss/**/*', | |
sassOpts: { | |
// outputStyle: 'nested', | |
// precison: 3, | |
errLogToConsole: true, | |
includePaths: [bootstrapSass.in + 'assets/stylesheets'] | |
} | |
}; | |
gulp.task('sass', function() { | |
return gulp.src(scss.in) // Gets all files ending with .scss in app/scss and child dirs (including bootstrap-sass files) | |
.pipe(sass(scss.sassOpts)) // Pass through a gulp-sass | |
.pipe(gulp.dest(scss.out)) // Outputs in dist folder | |
}); | |
// Watchers | |
gulp.task('watch', function() { | |
gulp.watch(scss.in, ['sass']).on('change', browserSync.reload); | |
gulp.watch('app/index.html').on('change', browserSync.reload); | |
gulp.watch('app/js/**/*.js').on('change', browserSync.reload); | |
}); | |
// Optimization Tasks | |
// ------------------ | |
// Optimizing CSS and JavaScript | |
gulp.task('useref', function() { | |
return gulp.src('app/*.html') | |
.pipe(useref()) | |
.pipe(gulpIf('*.js', uglify())) | |
.pipe(gulpIf('*.css', cssnano())) | |
.pipe(gulp.dest('dist')); | |
}); | |
// Optimizing Images | |
gulp.task('images', function() { | |
return gulp.src('app/images/**/*.+(png|jpg|jpeg|gif|svg)') | |
// Caching images that ran through imagemin | |
.pipe(cache(imagemin({ | |
interlaced: true, | |
}))) | |
.pipe(gulp.dest('dist/images')) | |
}); | |
// Copying fonts | |
gulp.task('fonts', function() { | |
return gulp.src(fonts.in) | |
.pipe(gulp.dest(fonts.out)) | |
}) | |
// Cleaning | |
gulp.task('clean', function() { | |
return del.sync('dist').then(function(cb) { | |
return cache.clearAll(cb); | |
}); | |
}) | |
gulp.task('clean:dist', function() { | |
return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*']); | |
}); | |
// Build Sequences | |
// --------------- | |
gulp.task('default', function(callback) { | |
runSequence(['sass', 'browserSync', 'watch'], | |
callback | |
) | |
}) | |
gulp.task('build', function(callback) { | |
runSequence( | |
'clean:dist', | |
['sass', 'useref', 'images', 'fonts'], | |
callback | |
) | |
}) |
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
{ | |
"name": "ENTER PROJECT NAME HERE", | |
"version": "0.0.1", | |
"description": "ENTER PROJECT DESCRIPTION HERE", | |
"main": "main.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Rouzbeh Sarrafieh", | |
"license": "ISC", | |
"devDependencies": { | |
"autoprefixer": "^6.3.7", | |
"bootstrap-sass": "^3.3.6", | |
"browser-sync": "^2.13.0", | |
"del": "1.2.1", | |
"gulp-autoprefixer": "^3.1.0", | |
"gulp-cache": "^0.4.5", | |
"gulp-cssnano": "^2.1.2", | |
"gulp-imagemin": "^3.0.1", | |
"gulp-postcss": "^6.1.1", | |
"gulp-sass": "^2.3.2", | |
"gulp-sourcemaps": "^1.6.0", | |
"gulp-uglify": "^1.5.4", | |
"gulp-useref": "^3.1.0", | |
"gulp-watch": "^4.3.8", | |
"run-sequence": "^1.2.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WIP....