【问题标题】:browser-sync is not auto refreshing浏览器同步不是自动刷新
【发布时间】:2017-06-07 05:16:19
【问题描述】:

我重新阅读了 grunt watch 页面上的指南,并在其他地方遵循了 3 个不同的示例,但是当 html 或 js 文件被修改时,我无法让它自动刷新我的页面......我的意思是我收到“文件已更改” :views/entryw.html" 消息,所以它被监视但没有自动重新加载/自动刷新的迹象

我的服务器在 9000 端口上运行

这就是我的 Gruntfile.js 的样子:

module.exports = function (grunt) {


    // --------------------------------------------------------------------------------------------- //
    // Configuration
    // --------------------------------------------------------------------------------------------- //
    grunt.initConfig({  
        browserSync: {
            bsFiles: {
                src : [
                    'forbiddenDirectory/*.js', 
                    'views/*.html'
                ]
            },
            /*options: {
                server: {
                    baseDir: "./"
                }
            }*/
            options: {
                proxy: "localhost:3000",
                open: false
            }
        }
    });


    // --------------------------------------------------------------------------------------------- //
    // Load plugins
    // --------------------------------------------------------------------------------------------- //
    grunt.loadNpmTasks('grunt-browser-sync');



    // --------------------------------------------------------------------------------------------- //
    // register tasks
    // --------------------------------------------------------------------------------------------- //
    grunt.registerTask('default', ['browserSync']);

    //grunt.registerTask('all', ['default']) // each index in array is the name of registered tasks above

}

【问题讨论】:

    标签: javascript browser-sync livereload


    【解决方案1】:

    我认为proxy option 应该像这样指向您的服务器的 9000 端口:

    options: {
      proxy: 'http://localhost:9000'
    }
    

    然后您可以通过http://localhost:3000 的浏览器同步访问您的应用程序,这将通过代理为端口 9000 上的实际服务器提供服务。

    YMMV,因为您的服务器可能需要重新启动才能使更改生效。

    【讨论】:

      猜你喜欢
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 2013-06-02
      • 2018-12-05
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多