Last active
December 31, 2015 16:11
-
-
Save brandedoutcast/a75a4995343f9661f874 to your computer and use it in GitHub Desktop.
Typical gulpfile.js template to start with for every web project
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
/// <binding ProjectOpened="default" /> | |
// #region Dependencies | |
var gulp = require("gulp"), | |
sass = require("gulp-sass"), | |
coffee = require("gulp-coffee"), | |
prefix = require("gulp-autoprefixer"), | |
nano = require("gulp-cssnano"), | |
uglify = require("gulp-uglify"), | |
del = require("del"), | |
plumber = require("gulp-plumber"), | |
notify = require("gulp-notify"); | |
// #endregion | |
// #region Variables | |
var resConfig = { | |
styles: { | |
compile: ["content/src/styles/style.scss"], | |
watch: ["content/src/styles", "content/src/styles/**/*.scss"], | |
outFile: "style.css" | |
}, | |
scripts: { | |
compile: ["content/src/scripts/**/*.coffee"], | |
watch: ["content/src/scripts", "content/src/scripts/**/*.coffee"], | |
outFile: "script.js" | |
}, | |
dist: "content", | |
}; | |
// #endregion | |
// #region Helpers | |
notify.logLevel(0); | |
var showError = notify.onError({ | |
title: "Error with [<%= error.plugin %>]", | |
message: "<%= error.line %> <%= error.file %> <%= error.toString() %>" | |
}); | |
// #endregion | |
// #region Tasks | |
// Convert SASS to CSS | |
gulp.task("beauty", function () { | |
del(resConfig.dist + "/" + resConfig.styles.outFile); | |
gulp.src(resConfig.styles.compile) | |
.pipe(plumber({ errorHandler: showError })) | |
.pipe(sass()) | |
.pipe(prefix()) | |
.pipe(nano()) | |
.pipe(gulp.dest(resConfig.dist)); | |
}); | |
// Convert CoffeeScript to JavaScript | |
gulp.task("beast", function () { | |
del(resConfig.dist + "/" + resConfig.scripts.outFile); | |
gulp.src(resConfig.scripts.compile) | |
.pipe(plumber({ errorHandler: showError })) | |
.pipe(coffee({ bare: true })) | |
.pipe(uglify()) | |
.pipe(gulp.dest(resConfig.dist)); | |
}); | |
// Watch files for changes | |
gulp.task("stalker", function () { | |
gulp.watch(resConfig.styles.watch, ["beauty"]); | |
gulp.watch(resConfig.scripts.watch, ["beast"]); | |
}); | |
// Default task | |
gulp.task("default", ["beauty", "beast", "stalker"]); | |
// #endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment