简体   繁体   English

如何在Laravel Homestead环境中使用gulp实时重新加载browsersync?

[英]How to live reload browsersync using gulp in laravel homestead environment?

I am trying to run Browsersync using gulp task runner within homestead laravel environment. 我正在尝试在宅基laravel环境中使用gulp任务运行器运行Browsersync。 Browsersync fires up in commander and when I make a change, Browsersync says it is "reloading browsers". Browsersync在Commander中启动,当我进行更改时,Browsersync说它正在“重新加载浏览器”。 It may well be, but I cannot see the reload in real-time unless I refresh the browser manually. 可能不错,但除非手动刷新浏览器,否则无法实时查看重新加载。

I tried mix and that worked, but I am using gulp to postcss, which I found difficult to set up in mix... 我尝试了混合,但效果很好,但是我正在使用gulp进行postcss,我发现很难在混合中进行设置...

var gulp = require('gulp'),
watch = require('gulp-watch'),
browserSync = require('browser-sync').create();

gulp.task('watch', function() {

    browserSync.init(null, {
        notify: false,
        port: 8000,
        host: '192.168.10.10',
        proxy: 'test.test',
        open: false,
        files: [
                'app/**/*.php',
                'resources/views/**/*.php',
                'public/js/**/*.js',
                'public/css/**/*.css'
        ],
        watchOptions: {
                usePolling: true,
                interval: 500
        }
    });

    watch('./resources/**/*.php', function() {
        browserSync.reload();
    });
});

I also added this: 我还添加了这个:

@if (getenv('APP_ENV') === 'local')
    <script id="__bs_script__">//<![CDATA[
        document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.js?v=2.18.12'><\/script>".replace("HOST", location.hostname));
        //]]>
    </script>
@endif

to main app php file but it made no difference to gulp browsersync setup. 到主应用程序php文件,但对gulp browsersync设置没有影响。 (Mix is running fine...). (Mix运行正常...)。

Please halp :) 请暂停:)

I am not 100% sure how your setup is, but i normally init brwoserSync just with : 我不是100%知道您的设置如何,但是我通常使用以下命令初始化brwoserSync:

browserSync.init({
  proxy: 'localhost:8000'
});

if my php server is running locally, i then can access it at http://localhost:3000 如果我的php服务器在本地运行,那么我可以在http:// localhost:3000上访问它

so i assume you are running a VM Ubuntu at IP 192.168.10.10 and port 8000, so this setup might work, but i'm not 100% sure yet 因此,我假设您正在IP 192.168.10.10和端口8000上运行VM Ubuntu,因此此设置可能有效,但我不确定100%

var gulp = require('gulp'),
watch = require('gulp-watch'),
browserSync = require('browser-sync').create();

gulp.task('watch', function() {

    browserSync.init(null, {
        notify: false,
        proxy: '192.168.10.10:8000',
        open: false,
        files: [
                'app/**/*.php',
                'resources/views/**/*.php',
                'public/js/**/*.js',
                'public/css/**/*.css'
        ],
        watchOptions: {
                usePolling: true,
                interval: 500
        }
    });

    watch('./resources/**/*.php', function() {
        browserSync.reload();
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM