2016-02-28 81 views
8

這個gulp文件有什麼問題?當它打開瀏覽器時,它不會顯示index.html。相反,它會列出'dist'的內容,該目錄包含index.html。Gulp-Connect列出目錄而不是顯示index.html。爲什麼?

"use strict"; 

var gulp = require('gulp'); 
var connect = require('gulp-connect'); // Runs a local dev server 
var open = require('gulp-open'); 

var config = { 
    port: 9005, 
    devBaseUrl: 'http://localhost', 
    paths: { 
     html: './src/*.html', 
     dist: './dist' 
    } 
}; 

//Start a local development server 
gulp.task('connect', function() { 
    connect.server({ 
     root: ['dist'], 
     port: config.port, 
     base: config.devBaseUrl, 
     livereload: true 
    }); 
}); 

gulp.task('open', ['connect'], function() { 
    gulp.src('dist/index.html') 
     .pipe(open({ 
      uri: config.devBaseUrl + ':' + config.port + '/', 
      app: 'chrome' })); 

}); 

gulp.task('html', function() { 
    gulp.src(config.paths.html) 
     .pipe(gulp.dest(config.paths.dist)) 
     .pipe(connect.reload()); 
}); 

gulp.task('watch', function() { 
    gulp.watch(config.paths.html, ['html']); 
}); 

gulp.task('default', ['html', 'open', 'watch']); 

回答

4

的解決方案是限制的版本一飲而盡,連接到"gulp-connect": "^2.2.0",最新版本的工作方式不同打開任務,但我不知道最新的正確語法。當我嘗試從另一張海報的答案時,該頁面按預期顯示,但手錶功能無法使用。

在撰寫本文時,當前版本是^ 3.0.0。

我在Windows 7上,如果這有所作爲。

[更新]根據@SteveDavis,這已在版本3.2.0中修復。

+1

這個技巧是一個救星。謝謝! –

+1

在3.2.0版中修復了此問題。 –

+0

感謝您的更新。 :-) –

0

你好問題是你的,你基本上是告訴一飲而盡打開dist目錄中,而不是僅僅的index.html

+0

我檢查。我正在從PluralSight的一個例子開始工作,就是這樣做的。它一度在工作。另外,在[npmjs.com](https://www.npmjs.com/package/gulp-open)上給出的例子就是這樣做的。 –

+0

如果我打破文檔並追加index.html,它會顯示在瀏覽器中,但'看'不起作用。 –

0

要安裝吞嚥連接插件的正確版本,請確保您輸入 npm install --save-dev [email protected]我有同樣的問題,並改回到該版本解決了它。

0

確保index.html的是src下不psadmin項目文件夾,因此它可以在那裏找到它時,它執行

gulp.src(config.paths.html) 
.pipe(gulp.dest(config.paths.dist) 
+0

你寫的與我寫的有什麼不同? –

相關問題