Skip to content

Instantly share code, notes, and snippets.

@oquirozm
Last active May 1, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oquirozm/2743757ecea1abbf75e3dfba2134d0d7 to your computer and use it in GitHub Desktop.
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.
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