为什么grunt-contrib-watch livereload无法正常运作?

扎克·莱索比(Zach Lysobey)

我正在努力获得Grunt的“实时重载”功能(已在中实现grunt-contrib-watch)才能在我的应用中工作。我终于忍住了子弹,并尝试提出一个最小的例子。希望有人可以轻松注意到所缺少的内容。

档案结构:

├── Gruntfile.js
├── package.json
├── index.html

package.json

{
  "name": "livereloadTest",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-watch": "~0.5.3"
  }
}

Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            src: {
                files: ['*.html'],
                options: { livereload: true }
            }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-watch');
};

index.html

<!doctype html>
<html>
<head><title>Test</title></head>
<body>

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

</body>
</html>

然后我跑步grunt watch,什么都没但是,没有浏览器窗口会自动打开(应该吗?)。

当我打开chrome时,http://localhost:35729/我收到以下json:

{"tinylr":"Welcome","version":"0.0.4"}

并尝试在该端口上的任何其他路径给我

{"error":"not_found","reason":"no such route"}
凯尔·罗宾逊·杨(Kyle Robinson Young)

http://localhost:35729/是实时重新加载服务器的URL。它仅用于管理实时重载,而不用于实际网站。

通常,人们会使用grunt-contrib-connect为grunt服务静态站点。然后通过转到localhost:8000或您将其配置为驻留的任何位置来查看其站点。但是根据您的需要,也可以是apache,nginx等提供文件。

livereload在grunt-contrib-connect上也有一个选项。这只会将<script src="//localhost:35729/livereload.js"></script>标记注入HTML,而不会注入其他标记。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

带livereload的grunt-contrib-watch,带vs,不带grunt-contrib-connect,带livereload

来自分类Dev

grunt-contrib-watch + grunt-rsync

来自分类Dev

Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

来自分类Dev

Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

来自分类Dev

Grunt watch livereload无法在MAMP上运行

来自分类Dev

如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

来自分类Dev

使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

来自分类Dev

grunt-contrib-watch + sass:如何指定目标文件?

来自分类Dev

grunt-contrib-watch:{tinylr:“ Welcome”,版本:“ 0.0.4”}

来自分类Dev

Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

来自分类Dev

grunt-contrib-watch未绑定递归错误

来自分类Dev

grunt-contrib-watch是否有不同的输出样式?

来自分类Dev

Grunt:contrib-watch编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

来自分类Dev

Grunt:contrib-watch当编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

来自分类Dev

在livereload中使用grunt watch

来自分类Dev

为什么$ watch无法启动

来自分类Dev

为什么$ watch无法启动

来自分类Dev

为什么这个Promise无法正常运作?

来自分类Dev

为什么有grunt-contrib-compass的javascriptsDir参数?

来自分类Dev

带有contrib-watch的grunt-express服务器

来自分类Dev

带有grunt-contrib-watch,browserify和hbsfy(把手)的Gruntfile-自动转换

来自分类Dev

在asp.net-vnext和Visual Studio 15中使用Grunt-Contrib-Watch

来自分类Dev

grunt-contrib-watch导致超出最大调用堆栈大小

来自分类Dev

grunt-watch正在跳过我的某些任务,为什么?

来自分类Dev

为什么这个Z-index无法正常运作?

来自分类Dev

为什么这个Z-index无法正常运作?

来自分类Dev

为什么我的ng-repeat无法正常运作?

来自分类Dev

无法使用grunt-contrib-cssmin创建缩小的CSS文件

来自分类Dev

grunt-contrib-sass无法编译CSS文件

Related 相关文章

  1. 1

    带livereload的grunt-contrib-watch,带vs,不带grunt-contrib-connect,带livereload

  2. 2

    grunt-contrib-watch + grunt-rsync

  3. 3

    Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

  4. 4

    Grunt-Live Reload无法与Grunt-Contrib-Watch配合使用

  5. 5

    Grunt watch livereload无法在MAMP上运行

  6. 6

    如何仅在需要时使用grunt-contrib-watch和grunt-contrib-coffee编译CoffeeScript?

  7. 7

    使用grunt-contrib-connect和grunt-contrib-watch进行实时重载

  8. 8

    grunt-contrib-watch + sass:如何指定目标文件?

  9. 9

    grunt-contrib-watch:{tinylr:“ Welcome”,版本:“ 0.0.4”}

  10. 10

    Gruntfile with grunt-contrib-watch, browserify, and hbsfy (handlebars) - Automate transform

  11. 11

    grunt-contrib-watch未绑定递归错误

  12. 12

    grunt-contrib-watch是否有不同的输出样式?

  13. 13

    Grunt:contrib-watch编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

  14. 14

    Grunt:contrib-watch当编译服务器端.coffee文件时,在重启grunt-nodemon后触发livereload事件

  15. 15

    在livereload中使用grunt watch

  16. 16

    为什么$ watch无法启动

  17. 17

    为什么$ watch无法启动

  18. 18

    为什么这个Promise无法正常运作?

  19. 19

    为什么有grunt-contrib-compass的javascriptsDir参数?

  20. 20

    带有contrib-watch的grunt-express服务器

  21. 21

    带有grunt-contrib-watch,browserify和hbsfy(把手)的Gruntfile-自动转换

  22. 22

    在asp.net-vnext和Visual Studio 15中使用Grunt-Contrib-Watch

  23. 23

    grunt-contrib-watch导致超出最大调用堆栈大小

  24. 24

    grunt-watch正在跳过我的某些任务,为什么?

  25. 25

    为什么这个Z-index无法正常运作?

  26. 26

    为什么这个Z-index无法正常运作?

  27. 27

    为什么我的ng-repeat无法正常运作?

  28. 28

    无法使用grunt-contrib-cssmin创建缩小的CSS文件

  29. 29

    grunt-contrib-sass无法编译CSS文件

热门标签

归档