Last active
August 29, 2015 14:26
-
-
Save mertkahyaoglu/14d01a4d2d0b95e907e8 to your computer and use it in GitHub Desktop.
Gulp for webapp (Node Server + Browserify + Less)
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'), | |
livereload = require('gulp-livereload'), | |
uglify = require('gulp-uglify'), | |
streamify = require('gulp-streamify'), | |
less = require('gulp-less'), | |
minifyCSS = require('gulp-minify-css'); | |
var paths = { | |
appjs: ['./public/js/app.js'], | |
css: ['./public/css/*.less'], | |
html: ['./public/*.html'], | |
dist: './public/dist/' | |
}; | |
gulp.task('js', function () { | |
browserify(paths.appjs).bundle() | |
.pipe(source('bundle.js')) | |
.pipe(streamify(uglify())) | |
.pipe(gulp.dest(paths.dist)) | |
.pipe(livereload()); | |
}); | |
gulp.task('css', function() { | |
return gulp.src(paths.css) | |
.pipe(less()) | |
.pipe(minifyCSS()) | |
.pipe(gulp.dest(paths.dist)) | |
.pipe(livereload()); | |
}); | |
gulp.task('html', function() { | |
return gulp.src(paths.html) | |
.pipe(livereload()); | |
}); | |
gulp.task('serve', function () { | |
nodemon({script: 'server.js'}) | |
}) | |
gulp.task('watch', function() { | |
livereload.listen(); | |
gulp.watch(paths.appjs, ['js']); | |
gulp.watch(paths.css, ['css']); | |
gulp.watch(paths.html, ['html']); | |
}); | |
gulp.task('default', ['js', 'css', 'serve', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment