gulp - 尝试使用 gulp 使 browsersync 在 vagrant 中工作

标签 gulp vagrant browser-sync

我一直在尝试使用 gulp 使 browsersync 在 vagrant 中工作。我可以连接到 browsersync 的 UI,但我永远无法连接到我的开发站点。如果尝试使用地址 http://localhost:3000 进行连接,我不断收到以下错误:

Cannot GET /

这是我对 vagrant 的配置:
  # IP Address to access the server 10.0.0.3
  config.vm.network "private_network", ip: "10.0.0.3"
  config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
  config.vm.network "forwarded_port", guest: 3001, host: 3001, auto_correct: true

  # Sync the server timezone to the host machine
  config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Manila /etc/localtime", run: "always"

  # Sync File
  config.vm.synced_folder "./", "/var/www/html", mount_options: ["dmode=777", "fmode=666"]

连接 SQL 时的配置

enter image description here

以下是我对 Gulp 的配置:
browserSync.init(["./assets/css/*.css"],{
    server: {
        proxy: "http://10.0.0.3/globe-gui/",
        open: false,
        port: "2222",
        injectChanges: true,
    }
});

enter image description here

我尝试在网上搜索解决方案,但似乎无法得到答案。

最佳答案

浏览器同步未使用 the correct options 初始化.

browserSync.init({
    files: ["./assets/css/*.css"],
    open: false,
    port: "2222",
    injectChanges: true,
    proxy: "http://10.0.0.3/globe-gui/",   
});

您的 Vagrantfile将客户机(框)配置为可通过 IP 地址访问 10.0.0.3 .

通过 IP 地址( 10.0.0.3 )从主机连接到盒子中运行的服务。

将 SSH 主机设置为 10.0.0.3用于在端口 2222 上运行的数据库服务从主机连接到盒子时在盒子中,但设置localhost在盒子内部连接时。

我认为 BrowserSync是在盒子里面开始的。

将代理配置为具有值:
proxy: "http://localhost/globe-gui/",

连接到 BrowserSync通过 box (http://10.0.0.3:3000) 的私有(private) IP 地址从在主机中运行的浏览器。

关于gulp - 尝试使用 gulp 使 browsersync 在 vagrant 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60445191/

相关文章:

gulp - Aurelia-Bundler 无法获取 aurelia-router.js

javascript - 使用 gulp 缩小 es2017

vagrant - 在 Vagrant 中使用 Atom 编辑器

console - Vagrant 向上 "error while executing VBoxManage"

javascript - gzip 编码 javascript 由本地节点服务器与浏览器同步提供服务

angular - BrowserSync 以未列出的访问 URL 开头

Gulp 4 watch 任务卡在 'Starting'

vagrant - "vagrant up"是否可能来自具有自定义 URL 的不同本地目录?

javascript - React 热模块替代方案——Rollup、Gulp 和 Browsersync

gulp - 如何以编程方式调用 Browsersync init 横幅?