Skip to content

Instantly share code, notes, and snippets.

@dmitriz
Forked from romaricpascal/Gulpfile.express.js
Created April 26, 2014 15:32
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 dmitriz/11323037 to your computer and use it in GitHub Desktop.
Save dmitriz/11323037 to your computer and use it in GitHub Desktop.
function startExpress() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(__dirname));
app.listen(4000);
}
// Don't forget to install `gulp-liverload` beforehand:
// `npm install gulp-livereload --save-dev`
function notifyLivereload(event) {
gulp.src(event.path, {read: false})
.pipe(require('gulp-livereload')(lr));
}
var gulp = require('gulp');
// Let's make things more readable by
// encapsulating each part's setup
// in its own method
function startExpress() {
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.listen(4000);
}
gulp.task('default', function () {
startExpress();
});
var gulp = require('gulp');
var EXPRESS_PORT = 4000;
var EXPRESS_ROOT = __dirname;
var LIVERELOAD_PORT = 35729;
// Let's make things more readable by
// encapsulating each part's setup
// in its own method
function startExpress() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
}
// We'll need a reference to the tinylr
// object to send notifications of file changes
// further down
var lr;
function startLivereload() {
lr = require('tiny-lr')();
lr.listen(LIVERELOAD_PORT);
}
// Notifies livereload of changes detected
// by `gulp.watch()`
function notifyLivereload(event) {
// `gulp.watch()` events provide an absolute path
// so we need to make it relative to the server root
var fileName = require('path').relative(EXPRESS_ROOT, event.path);
lr.changed({
body: {
files: [fileName]
}
});
}
// Default task that will be run
// when no parameter is provided
// to gulp
gulp.task('default', function () {
startExpress();
startLivereload();
gulp.watch('*.html', notifyLivereload);
});
var gulp = require('gulp');
// `gulp.task()` defines task that can be run calling `gulp xyz` from the command line
// The `default` task gets called when no task name is provided to Gulp
gulp.task('default', function () {
console.log('Gulp and running!')
});
// https://github.com/sindresorhus/jshint-stylish example
gulp.task('default', function () {
gulp.src(['file.js'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
// ...
// We'll need a reference to the tinylr
// object to send notifications of file changes
var lr;
function startLivereload() {
lr = require('tiny-lr')();
lr.listen(35729);
}
// Default task that will be run
// when no parameter is provided
// to gulp
gulp.task('default', function () {
startExpress();
startLivereload();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment