Created
August 10, 2015 10:20
-
-
Save mertkahyaoglu/442a3a2d3de68d46df5b to your computer and use it in GitHub Desktop.
Gulp for webapp (Node + LESS + BrowserSync)
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
// npm install --global gulp to use from terminal | |
// npm install gulp for a project | |
var gulp = require('gulp'), | |
browserify = require('browserify'), | |
source = require('vinyl-source-stream'), | |
nodemon = require('gulp-nodemon'), | |
uglify = require('gulp-uglify'), | |
streamify = require('gulp-streamify'), | |
less = require('gulp-less'), | |
minifyCSS = require('gulp-minify-css'), | |
browserSync = require('browser-sync'), | |
reload = browserSync.reload; | |
var paths = { | |
appjs: ['./public/js/app.js'], | |
css: ['./public/css/*.less'], | |
dist: './public/dist/', | |
html: ['./public/*.html'] | |
}; | |
gulp.task('js', function () { | |
return browserify(paths.appjs).bundle() | |
.pipe(source('bundle.js')) // converts to stream | |
.pipe(streamify(uglify())) // streaming uglify | |
.pipe(gulp.dest(paths.dist)) // output | |
.pipe(reload({stream:true})); // reload on change | |
}); | |
gulp.task('css', function() { | |
return gulp.src(paths.css) | |
.pipe(less()) // compile to css | |
.pipe(minifyCSS()) // minify | |
.pipe(gulp.dest(paths.dist)) // output | |
.pipe(reload({stream:true})); // reload on change | |
}); | |
gulp.task('html', function() { | |
return gulp.src(paths.html) | |
.pipe(reload({stream:true})); // reload on change | |
}); | |
gulp.task('browser-sync', ['serve'], function() { | |
browserSync.init({ | |
server: { | |
baseDir: "./public" | |
} | |
}); | |
}); | |
gulp.task('serve', ['watch'], function () { | |
nodemon({script: 'server.js'}) //start server | |
}) | |
gulp.task('watch', function() { | |
//watch files | |
gulp.watch(paths.css, ['css']); | |
gulp.watch(paths.html, ['html']); | |
gulp.watch(paths.appjs, ['js']); | |
}); | |
gulp.task('default', ['js', 'css', 'browser-sync']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment