2015-11-13 91 views
4

我有一個問題,我的吞噬網絡服務器。我有這樣一口任務:吞噬網絡服務器和livereload

gulp.task('serve', ['watch'],() => { 
    gulp.src('tmp') 
    .pipe(webserver({ 
     livereload: true, 
     directoryListing: true, 
     open: true, 
     //defaultFile: 'index.html' 
    })); 
}); 

當運行gulp serve我正在本地主機下面的畫面:8000:
localhost:8000

好像是網絡服務器的服務我的項目的根目錄下,而不是tmp文件夾,奇怪的是如果我點擊index.html我被重定向到http://localhost:8000/index.html這是正確的文件(tmp/index.html而不是/index.html)。

我使用gulp-webserver進行服務和實時刷新。

我做錯了什麼?

注意:取消註釋defaultFile沒有幫助。

+1

如果只dev的,你應該看看'browserSync'而不是使用網絡服務器 –

+0

@ArnaudGueras Browsersync - https://browsersync.io/docs/gulp直遠離工作對我來說 - 感謝提示! – Matt

回答

3

您可以將對象傳遞到directoryListing以調整此設置。

.pipe(webserver({ 
    directoryListing: { 
    enable: true, 
    path: 'tmp' 
    } 
})); 

詳情: https://github.com/schickling/gulp-webserver#options

+0

它不會等待依賴任務完成,並在任何源文件更改後立即觸發頁面重新加載。它需要手動刷新頁面。這可以修復嗎? – JVM

0

試試這個

gulp.task('serve', ['watch'],() => { 
     gulp.src('./tmp') 
     .pipe(webserver({ 
     livereload: true, 
     directoryListing: true, 
     open: true, 
     //defaultFile: 'index.html' 
    })); 
    });