-
-
Save edm00se/08bedba23919af3e1c138f0c048583ac to your computer and use it in GitHub Desktop.
task runner pt 3 gulp code snippets
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
// 1 define the plugin imports | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
jshint = require('gulp-jshint'); | |
/* 2 define the tasks, including the | |
* default task, aka- no args when running 'gulp' | |
*/ | |
gulp.task('default', ['jshint','watch']); | |
// note, order doesn't matter | |
gulp.task('jshint', function() { | |
return gulp.src(['./NSF/WebContent/js/*.js']) | |
.pipe(jshint({ | |
// any options for config of the jshint functionality | |
})) | |
.pipe(jshint.reporter('jshint-stylish')); | |
}); | |
/* Watch these files for changes and run the task on update */ | |
gulp.task('watch', function() { | |
gulp.watch(input.javascript, ['jshint']); | |
}); |
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
/* File: gulpfile.js */ | |
// grab our packages | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
jshint = require('gulp-jshint'), | |
jsonServer = require('gulp-json-srv'), | |
server = jsonServer.start({ // config the json-server instance | |
data: 'db.json', | |
id: 'unid', | |
rewriteRules: { | |
"/xsp/houses": "/houses", | |
"/xsp/:houses/:id": "/:houses/:id", | |
"/xsp/characters": "/characters", | |
"/xsp/:characters/:id": "/:characters/:id" | |
}, | |
deferredStart: true | |
}), | |
browserSync = require('browser-sync').create(); | |
// configure the jshint task | |
gulp.task('jshint', function() { | |
return gulp.src(['./NSF/WebContent/js/*.js']) | |
.pipe(jshint({ | |
'-W033': true, // mising semicolon | |
'-W041': true, // use 'x' to compare with 'y' | |
'-W004': true, // x already in use | |
'-W014': true // bad line breaking before '||' | |
})) | |
.pipe(jshint.reporter('jshint-stylish')); | |
}); | |
// configure which files to watch and what tasks to use on file changes | |
gulp.task('watch', function() { | |
gulp.watch('./NSF/WebContent/js/*.js', ['jshint','browser-sync-reload']); | |
gulp.watch(['db.json'], function(){ server.reload(); }); | |
}); | |
// starts the json-server instance | |
gulp.task('serverStart', function(){ server.start(); }); | |
// reload the json-server instance, and its assets | |
gulp.task('serverReload', function(){ server.reload(); }); | |
// loading browser-sync as a proxy, must load after json-server | |
gulp.task('browser-sync', function() { | |
browserSync.init({ | |
proxy: "http://localhost:3000/", | |
ui: { | |
weinre: { | |
port: 9090 | |
} | |
} | |
}); | |
}); | |
// reload browserSync | |
gulp.task('browser-sync-reload', function(){ browserSync.reload(); }); | |
// define the default task and add the watch task to it | |
gulp.task('default', ['watch','serverStart','browser-sync']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment