【问题标题】:Gulp browser-sync where place folder?Gulp 浏览器同步在哪里放置文件夹?
【发布时间】:2014-12-30 10:05:53
【问题描述】:

我安装了插件浏览器同步。在命令行粘贴 gulp browser-sync 并在 firefox 显示地址 http://localhost:3000/ 的“Cannot GET /

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'
  }
 });
});

文件夹 app 放在 Node.js 的根目录下。我不使用任何 LAMP 或 WAMP,因为我不能使用它。还有其他解决问题的方法吗? (更改源代码后在浏览器中重新加载页面)。

谢谢

【问题讨论】:

    标签: javascript gulp browser-sync


    【解决方案1】:

    我相信这是因为浏览器同步不知道,如果没有额外的配置,当你没有指定要查看的显式文件时该怎么做。通常,当指定目录时,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 */}); 进行初始化,请参阅 http://www.browsersync.io/docs/gulp/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 2015-04-15
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      相关资源
      最近更新 更多