Last active
January 25, 2018 01:17
-
-
Save patrickng/34b7822ab48c89fb1fad to your computer and use it in GitHub Desktop.
Gulp SASS + Live Reload + 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'), | |
gutil = require('gulp-util'), | |
sass = require('gulp-sass'), | |
sourcemaps = require('gulp-sourcemaps'), | |
livereload = require('gulp-livereload'), // Livereload plugin needed: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei | |
autoprefixer = require('gulp-autoprefixer'), | |
uglify = require('gulp-uglify'), | |
concat = require('gulp-concat'); | |
var onError = function (err) { | |
gutil.beep(); | |
gutil.log(gutil.colors.red(err.message)); | |
this.emit('end'); | |
}; | |
// --- Basic Tasks --- | |
gulp.task('sass', function() { | |
return gulp.src(['scss/style_debug.scss','scss/style3_debug.scss']) | |
.pipe(plumber({ | |
errorHandler: onError | |
})) | |
.pipe(sourcemaps.init()) | |
.pipe(sass({ errLogToConsole: true })) | |
.pipe(autoprefixer({ | |
browsers: ['last 2 versions', 'IE 9'] | |
})) | |
.pipe(sourcemaps.write('../maps')) | |
.pipe(gulp.dest('htdocs/css')) | |
.pipe(livereload()); | |
}); | |
gulp.task('sass-production', function() { | |
return gulp.src(['scss/style.scss', 'scss/style3.scss']) | |
.pipe(plumber()) | |
.pipe(sass()) | |
.pipe(autoprefixer({ | |
browsers: ['last 2 versions', 'IE 9'] | |
})) | |
.pipe(gulp.dest('htdocs/css')); | |
}); | |
gulp.task('js', function() { | |
return gulp.src(['htdocs/js/**/*.js']) | |
.pipe(plumber()) | |
.pipe(sourcemaps.init()) | |
.pipe(concat('build.js')) | |
.pipe(sourcemaps.write('../maps')) | |
.pipe(gulp.dest('htdocs/js')); | |
}); | |
gulp.task('js-production', function() { | |
return gulp.src(['htdocs/js/**/*.js']) | |
.pipe(plumber()) | |
.pipe(concat('build.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('htdocs/js')); | |
}); | |
gulp.task('watch', function() { | |
livereload.listen(35729, function(err) { | |
if (err) { | |
return console.log(err); | |
} | |
gulp.watch('scss/**/*.scss', ['sass']); | |
gulp.watch(['htdocs/index.php', 'application/views/**/*.php', 'htdocs/js/**/*.js']).on('change', function(file) { | |
livereload.changed(file.path); | |
gutil.log(gutil.colors.yellow('File changed' + ' (' + file.path + ')')); | |
}); | |
}); | |
}); | |
// Default Task | |
gulp.task('default', ['css', 'js', 'watch']); | |
gulp.task('build', ['sass-production', 'js-production']); |
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": "gulp", | |
"version": "0.1.0", | |
"description": "Gulp Recipe - Sass, LiveReload, JS", | |
"author": "Patrick Ng", | |
"devDependencies": { | |
"browser-sync": "^2.7.13", | |
"gulp": "~3.9.0", | |
"gulp-autoprefixer": "^2.3.1", | |
"gulp-concat": "^2.6.0", | |
"gulp-livereload": "^3.8.0", | |
"gulp-plumber": "^1.0.1", | |
"gulp-sass": "~2.0.3", | |
"gulp-uglify": "^1.2.0", | |
"gulp-util": "~3.0.6", | |
"gulp-sourcemaps": "~1.5.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment