Last active
May 1, 2017 08:38
-
-
Save oquirozm/2743757ecea1abbf75e3dfba2134d0d7 to your computer and use it in GitHub Desktop.
This is a gulpfile with a very basic setup that includes js and css directories and minifying of both + browsersync live reload.
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 bs = require('browser-sync').create(); | |
var gutil = require('gulp-util'); | |
var uglify = require('gulp-uglify'); | |
var cleanCSS = require('gulp-clean-css'); | |
var htmlreplace = require('gulp-html-replace'); | |
var rename = require('gulp-rename'); | |
gulp.task('default', ['compile','browser-sync', 'watch']); | |
gulp.task('compile', ['js-minify', 'css-minify']); | |
gulp.task('browser-sync', function() { | |
bs.init({ | |
server: { | |
baseDir: "./" | |
} | |
}); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('./index.html').on('change',bs.reload); | |
gulp.watch('js/script.js', ['js-minify']); | |
gulp.watch('css/style.css', ['css-minify']); | |
}) | |
gulp.task('js-minify', function() { | |
gulp.src('js/script.js') | |
.pipe(uglify()) | |
.pipe(rename('script.min.js')) | |
.pipe(gulp.dest('./js')) | |
.pipe(bs.stream()); | |
}); | |
gulp.task('css-minify', function() { | |
gulp.src('css/style.css') | |
.pipe(cleanCSS({ level : 2 })) | |
.pipe(rename('style.min.css')) | |
.pipe(gulp.dest('./css')) | |
.pipe(bs.stream()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment