Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. ## Speedup Node.js web app development workflow with gulp, gulp-nodemon, browser-sync
  2.  
  3. _by __nguyentd___
  4.  
  5. ```
  6. npm i -g gulp-cli
  7. ```
  8.  
  9. ```
  10. cd ~/Projects/node-js-app
  11. npm i -D gulp gulp-nodemon browser-sync
  12. touch gulpfile.js
  13. ```
  14.  
  15. ```javascript
  16. const gulp = require('gulp')
  17. const nodemon = require('gulp-nodemon')
  18. const browserSync = require('browser-sync').create()
  19. ```
  20.  
  21. ```javascript
  22. gulp.task('nodemon', () => {
  23. return nodemon({
  24. script: 'app.js'
  25. })
  26. })
  27. ```
  28.  
  29. ```javascript
  30. gulp.task('nodemon', (callback) => {
  31. let isCallbackCalled = false
  32. return nodemon({
  33. script: 'app.js'
  34. }).on('start', () => {
  35. if(!isCallbackCalled) {
  36. callback()
  37. isCallbackCalled = true
  38. }
  39. })
  40. })
  41. ```
  42.  
  43. ```javascript
  44. gulp.task('browser-sync', ['nodemon'], () => {
  45. browserSync.init({
  46. proxy: 'localhost:6969',
  47. port: 5969
  48. files: [
  49. './src/views/*.*',
  50. './public/*.css'
  51. ]
  52. })
  53. })
  54. ```
  55.  
  56. ```javascript
  57. gulp.task('default', ['browser-sync'], () => {})
  58. ```
  59.  
  60. ```
  61. gulp
  62. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement