如何让 gulp + browsersync 运行 apache vhost? [英] How do I get gulp + browsersync to work an apache vhost?

查看:16
本文介绍了如何让 gulp + browsersync 运行 apache vhost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 gulp、sass 和 browsersync 添加到我的工具包中.我现在正在运行配置了 sass 和 browsersync 任务的 gulp.

I'd like to add gulp, sass and browsersync to my toolkit. I'm now running gulp with a sass and browsersync task configured.

我正在为我的本地 apache 服务器上的虚拟主机运行一个 php 应用程序皮肤.

I'm skinning a php app running from a vhost on my local apache server.

我正在尝试从监视任务运行 browsersync,使用 browsersync 的代理选项来使用我的虚拟主机.

I'm attempting to run browsersync from a watch task, using the browsersync's proxy option to use my vhost.

目前,当我运行手表时,在端口 3000 上找不到服务器.如果我导航到 'localhost:3000',我会收到 chrome 'no web page found' 消息.

Currently, when I run the watch no server can be found on port 3000. If I navigate to 'localhost:3000' I get chromes 'no web page found' message.

如果我导航到端口 3001,我可以访问 browsersync 的管理 UI.所以我知道 browsersync 正在运行.

If I navigate to port 3001 I can access browsersync's admin UI. So I know that browsersync is running.

我的 gulp 配置如下

My gulp conf is as follows

/* load plugins */
var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    browsersync  = require('browser-sync') ;

/*
*  define tasks
*/

gulp.task('sass', function() {
    return sass('assets/sass/main.sass') ;        
}) ;


/*
*  browsersync conf
*/

gulp.task('browser-sync', function() {
    browsersync({
    proxy: 'localhost',
    port: '3000'
    });
});

gulp.task('browsersync-reload', function () {
    browsersync.reload();
});

gulp.task('watch', ['browser-sync'], function () {
  gulp.watch('assets/sass/**/*', ['css']);
});


/* Default task */
gulp.task('default', ['sass'], function() {
    gulp.watch("assets/sass/**.*", ['sass']);
});

推荐答案

如果你已经安装了 apache (sample with mamp) 你必须配置端口为 8080

If you have installed apache (sample with mamp) you must configure the port at 8080

我的配置:

 browserSync.init({
      open: 'external',
      host: 'local.dev',
      proxy: 'local.dev',
      port: 8080 // for work mamp
});

这篇关于如何让 gulp + browsersync 运行 apache vhost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆