Last active
March 19, 2017 18:49
-
-
Save nmabhinandan/03e5c363f4e14760337c to your computer and use it in GitHub Desktop.
Express Nodemon BrowserSync Gulp
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 babel = require('gulp-babel'); | |
var uglify = require('gulp-uglify'); | |
var sass = require('gulp-sass'); | |
var sourcemaps = require("gulp-sourcemaps"); | |
var postcss = require('gulp-postcss'); | |
var autoprefixer = require('autoprefixer'); | |
var cssnano = require('cssnano'); | |
var nodemon = require('gulp-nodemon'); | |
var path = require('path'); | |
var concat = require('gulp-concat'); | |
var browserSync = require('browser-sync').create(); | |
var reload = browserSync.reload; | |
gulp.task('js', function() { | |
return gulp.src('./public/js/*.js') | |
.pipe(sourcemaps.init()) | |
.pipe(babel({ | |
stage: 0 | |
})) | |
.pipe(concat('script_dist.js')) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('./public/dist')) | |
.pipe(reload({stream:true})); | |
}); | |
gulp.task('sass', function() { | |
return gulp.src('./public/styles/style.scss') | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(postcss([ | |
autoprefixer({browsers: ['last 4 version']}), | |
cssnano(), | |
])) | |
.pipe(gulp.dest('./public/dist')) | |
.pipe(reload({stream:true})); | |
}); | |
gulp.task('nodemon', function (cb) { | |
var called = false; | |
return nodemon({ | |
script: 'server.js', | |
ext: '.js .hbs', | |
ignore: [ | |
'public/**/*.js', | |
'node_modules/**/*.js' | |
], | |
env: { | |
'NODE_ENV': 'development', | |
'PORT': 8888 | |
}, | |
}).on('start', function () { | |
if (!called) { | |
called = true; | |
cb(); | |
} | |
}).on('restart', function () { | |
console.log('Ndoemon restarted!'); | |
}); | |
}); | |
gulp.task('browser-sync', ['nodemon'], function() { | |
browserSync.init({ | |
proxy: "localhost:8888" | |
}); | |
}); | |
gulp.task('build', ['js', 'sass']); | |
gulp.task('default', ['sass', 'js', 'browser-sync'], function () { | |
gulp.watch('./public/styles/**/*.scss', ['sass']); | |
gulp.watch('./public/js/**/*.js', ['js']); | |
gulp.watch('./views/**/*.hbs', reload); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment