BrowserSync Gulp 无法在 Chrome 中打开

我尝试在 Chrome 中使用 BrowserSync 和 Gulp 在本地主机上打开我的网站,但它不起作用.默认情况下,它在 Firefox 中打开,一切正常.但是,当我更改 gulpfile.js 中的参数以在 Chrome 中打开网站时 - 我有以下信息:

I try to open my website on localhost using BrowserSync and Gulp in Chrome, but it doesn't work. Default, it open in Firefox and everything works well. But, when I change params in gulpfile.js to open website in Chrome - I have this information:

[Browsersync] 无法打开浏览器(如果您在无头环境,您可能希望将 open 选项设置为 false)我在 gulpfile.js 中的配置:

[Browsersync] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false) My config in gulpfile.js:

// browser-sync options
// see: https://www.browsersync.io/docs/options/
var browserSyncOptions = {
    browser: "google chrome",
    proxy: "localhost",
    notify: false
};

我尝试了chrome"、chrome-browser",但没有任何反应.我应该怎么做?注意:我有 Ubuntu 17.04,Chrome 是我的默认浏览器.

I tried "chrome", "chrome-browser", nothing happend. What I should to do? Notice: I have Ubuntu 17.04, Chrome is my default browser.

推荐答案

我认为问题出在您的端口上,尝试将您的代理更改为以下:

I think the issue is with your port, try to change your proxy to below :

var browserSyncOptions = {
    browser: "google chrome",
    proxy: "localhost:3001",
    notify: false
};

并使用此端口在 chrome 中检查您的网站:

and check your website in chrome with this port :

http://localhost:3001

更新:

也尝试在 browserSync 中使用相同的端口:

Also try to use the same port in browserSync :

browserSync({ 
   proxy: 'localhost:3001' 
}); 

相关文章