2015-09-28 47 views
3

我想設置gulp觀看1件事:服務器的來源。在源更新後,服務器節點腳本將通過&開始客戶端瀏覽器刷新。gulp手錶 - gulp-nodemon - 應用程序崩潰

我相信我需要爲服務器一飲而盡,nodemon,而瀏覽器同步客戶端。

服務器的腳本由執行:節點的src \ babel.js
該腳本運行時,這種方式,而是通過我的配置爲咕嘟咕嘟失敗。

有什麼我做錯了嗎?

這是我的任務腳本:

var gulp = require('gulp'); 
var browserSync = require('browser-sync'); 
var nodemon = require('gulp-nodemon'); 



gulp.task('default', ['watchServer', 'watchClient']); 

gulp.task('watchServer', function() { 
    gulp.watch('src/**', function() { 
     nodemon({ // called upon update 
      script: 'src/babel.js', // I have tried both/& \\ 
     }) 
    }); 

    nodemon({ // called on start 
     script: 'src/babel.js', // I have tried both/& \\ 
    }) 
}); 

gulp.task('watchClient', function() { 
    browserSync({ 
     open: 'external', 
     host: '████████', 
     port: 80, 
     ui: false, 
     server: { 
      // We're serving the src folder as well 
      // for sass sourcemap linking 
      baseDir: ['src'] 
     }, 
     files: [ 
     'src/**' 
     ] 
    }); 
}); 

登錄:

> gulp 

[02:28:04] Using gulpfile B:\Test Server\gulpfile.js 
[02:28:04] Starting 'watchServer'... 
[02:28:04] Finished 'watchServer' after 19 ms 
[02:28:04] Starting 'watchClient'... 
[02:28:04] Finished 'watchClient' after 27 ms 
[02:28:04] Starting 'default'... 
[02:28:04] Finished 'default' after 9.66 μs 
[02:28:04] [nodemon] 1.7.1 
[02:28:04] [nodemon] to restart at any time, enter `rs` 
[02:28:04] [nodemon] watching: *.* 
[02:28:04] [nodemon] starting `node src\babel.js` 
[BS] Access URLs: 
----------------------------------- 
    Local: http://localhost:80 
External: http://████████:80 
----------------------------------- 
[BS] Serving files from: src 
[BS] Watching files... 
events.js:141 
     throw er; // Unhandled 'error' event 
    ^

Error: listen EADDRINUSE :::80 
    at Object.exports._errnoException (util.js:837:11) 
    at exports._exceptionWithHostPort (util.js:860:20) 
    at Server._listen2 (net.js:1231:14) 
    at listen (net.js:1267:10) 
    at Server.listen (net.js:1363:5) 
    at B:/Test Server/src/app/app.jsx:17:7 
    at Object.<anonymous> (B:/Test Server/src/app/app.jsx:41:2) 
    at Module._compile (module.js:434:26) 
    at normalLoader (B:\Test Server\node_modules\babel-core\lib\api\register\node.js:199:5) 
    at Object.require.extensions.(anonymous function) [as .jsx] (B:\Test Server\node_modules\babel-core\lib\api\register\node.js:216:7) 
[02:28:05] [nodemon] app crashed - waiting for file changes before starting... 

回答

2

你並不需要看與一飲而盡服務器的文件,因爲當它改變nodemon會自動重新啓動,你可以試試這在你的配置

gulp.task('watchServer', function() { 
    // remove the gulp.watch entry 

    nodemon({ // called on start 
     script: 'src/babel.js', // I have tried both/& \\ 
     ext: 'js', 
     watch: ['src/babel.js'] 
    }) 
}); 

似乎還有其他東西運行在端口80(噸他是apache的默認端口)所以它可能有助於將端口瀏覽器同步運行到類似於4000

如果您的節點服務器運行在我們說的端口3000上,您將需要使用browsersync代理它。

gulp.task('watchClient', function() { 
    browserSync({ 
     open: 'external', 
     host: '████████', 
     proxy: '[YOURHOST]:3000' 
     port: 4000, 
     ui: false, 
     // this entry will most likely need to be removed 
     // if you are using something like express as a static server 
     server: { 
      // We're serving the src folder as well 
      // for sass sourcemap linking 
      baseDir: ['src'] 
     }, 
     files: [ 
     'src/**' 
     ] 
    }); 
});