【问题标题】:Grunt Livereload through grunt-contrib-watch not refreshing browserGrunt Livereload 通过 grunt-contrib-watch 不刷新浏览器
【发布时间】:2017-03-18 06:22:38
【问题描述】:

我对 Grunt 很陌生,我正在尝试通过 grunt-contrib-watch 插件启用 livereload,但我的浏览器没有刷新。这是我当前的 Gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        watch: {
            options: {
                livereload: true
            },
            files: ['*.html']
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
};

我在与 Gruntfile.js 相同的文件夹中有一个 index.html 文件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Grunt example</title>
</head>
<body>
    <h1>Grunt example</h1>
    <p>A paragraph</p>
    <script src="//localhost:35729/livereload.js"></script>
</body>
</html>

所以我执行“grunt watch”并在更改 index.html 文件后从控制台收到以下消息:

文件“index.html”已更改。 在 0.000 秒内完成...

但是我的浏览器没有刷新。我错过了什么吗?有什么错误吗?

【问题讨论】:

    标签: gruntjs grunt-contrib-watch


    【解决方案1】:

    从以下位置更改您的脚本块:

    <script src="//localhost:35729/livereload.js"></script>
    

    收件人:

    <script src="http://localhost:35729/livereload.js"></script>
    

    应该修复它。

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 2014-04-25
      • 2014-03-21
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多