我如何获得gulp + browsersync来运行Apache vhost? [英] How do I get gulp + browsersync to work an apache vhost?

查看:132
本文介绍了我如何获得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.

我试图从watch任务运行浏览器同步,使用浏览器同步的代理选项来使用我的虚拟主机。

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

目前,当我运行手表时,在端口3000上找不到服务器。如果我导航到'localhost:3000',我会得到chromes'找不到网页'的消息。

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正在运行。

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

我的gulp conf如下所示:

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必须将端口配置为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天全站免登陆