簡體   English   中英

Gulp瀏覽器同步在哪里放置文件夾?

[英]Gulp browser-sync where place folder?

我安裝了插件Browser-sync。 在命令行上,粘貼了gulp browser-sync並且在Firefox中顯示了“ 無法獲取/ ”地址http://localhost:3000/

gulpfile.js中是:

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

gulp.task('browser-sync', function () {
 var files = [
  'app/**/*.html',
 ];

 browserSync.init(files, {
  server: {
     baseDir: './app'
  }
 });
});

文件夾應用程序放置在Node.js的根目錄中。 我不使用任何LAMP或WAMP,因為我無法使用它。 還有其他解決方法嗎? (更改源代碼后在瀏覽器中重新加載頁面)。

謝謝

我認為這是因為在沒有其他配置的情況下,瀏覽器同步不知道在不指定要查看的顯式文件時該怎么做。 通常,指定目錄后,Web服務器默認會查看index.html。

要查看是否是這種情況,請轉到http://localhost:3000/index.html ,假設您直接在“ app”目錄下有一個index.html(例如,存在app / index.html)。

要“修復”此問題,請在服務器配置中添加以下參數之一:

  1. index: "index.html" (顯示index.html)
  2. directory: true (顯示目錄列表)

有關更多配置選項,請參見http://www.browsersync.io/docs/options/

此外,第一個參數可能是不必要的。 我建議嘗試以下

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

gulp.task('browser-sync', function () {
 browserSync.init(null, {
  server: {
     baseDir: 'app',
     directory: true // or index: "index.html"
  }
 });
});

顯然,在較新版本的瀏覽器同步中,只需使用browserSync({ /* options */});即可將其初始化browserSync({ /* options */}); ,請參閱http://www.browsersync.io/docs/gulp/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM