Advertisement
Guest User

Untitled

a guest
May 30th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. var gulp = require('gulp');
  2.  
  3. var EXPRESS_PORT = 4000;
  4. var EXPRESS_ROOT = __dirname;
  5. var LIVERELOAD_PORT = 35729;
  6.  
  7. // Let's make things more readable by
  8. // encapsulating each part's setup
  9. // in its own method
  10. function startExpress() {
  11.  
  12. var express = require('express');
  13. var app = express();
  14. app.use(require('connect-livereload')());
  15. app.use(express.static(EXPRESS_ROOT));
  16. app.listen(EXPRESS_PORT);
  17. }
  18.  
  19. // We'll need a reference to the tinylr
  20. // object to send notifications of file changes
  21. // further down
  22. var lr;
  23. function startLivereload() {
  24.  
  25. lr = require('tiny-lr')();
  26. lr.listen(LIVERELOAD_PORT);
  27. }
  28.  
  29. // Notifies livereload of changes detected
  30. // by `gulp.watch()`
  31. function notifyLivereload(event) {
  32.  
  33. // `gulp.watch()` events provide an absolute path
  34. // so we need to make it relative to the server root
  35. console.log("Notifylivereoload triggeres")
  36. var fileName = require('path').relative(EXPRESS_ROOT, event.path);
  37.  
  38. lr.changed({
  39. body: {
  40. files: [fileName]
  41. }
  42. });
  43. }
  44.  
  45. // Default task that will be run
  46. // when no parameter is provided
  47. // to gulp
  48. gulp.task('default', function () {
  49.  
  50. startExpress();
  51. startLivereload();
  52. //**********THIS IS WHERE YOU SPECIFY THE TYPE OF FILES YOU WANT TO WATCH FOR.
  53. //IN THIS CASE, YOU ARE WATCHING FOR CHANGES IN HTML AND CSS**************
  54. gulp.watch('*.html', notifyLivereload);
  55. //Note, the relative path must be used for specifying the type of files. In this case, the below statement
  56. //specifies that that gulp should watch for changes in all CSS files within the ./css/ folder.
  57. gulp.watch('css/*.css', notifyLivereload);
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement