在使用grunt的虚拟机上使用liverload时出错

Error using LiveReload on virtual machine with grunt

本文关键字:liverload 出错 grunt 虚拟机      更新时间:2023-09-26

我正在使用一个装有vagrant/puphpet (ubuntu 12.04)的virtualbox。我成功地设置了grunt和contrib-watch。我安装了chrome扩展…此处指定的所有内容:https://github.com/gruntjs/grunt-contrib-watch#live-reloading

我的Gruntfile如下:

module.exports = function(grunt)
{
require('load-grunt-tasks')(grunt);
grunt.initConfig({
  compass: {                  // Task
    dist: {                   // Target
      options: {              // Target options
        sassDir:        'sass',
        cssDir:         'css',
        environment:    'development',
        httpPath:       '/',
        imagesDir:      'img',
        relativeAssets:  true
      }
    }
  },
watch: {
    options: { livereload: true },
    sass: {
        files: ['sass/**/*.scss'],
        tasks: ['compass'],
        options: { spawn: false }
    }
}
});
grunt.registerTask('default', ['compass']);
}

我运行命令"grunt watch",它处理我的sass正确。但在Chrome的控制台,我得到以下错误:

GET http://127.0.0.1:35729/livereload.js?ext=Chrome&extver=2.0.9
net::ERR_CONNECTION_REFUSED  injected.js:116

如果我在我的视图中手动添加脚本,我仍然得到错误:

GET http://localhost:35729/livereload.js net::ERR_CONNECTION_REFUSED 

你知道这个错误是怎么来的吗?

你的gruntfile看起来不错。

看起来您的虚拟机拒绝连接。请确保在iptables中打开了实时重新加载端口。

在Ubuntu中,可以简单地使用ufw:

sudo apt-get install ufw
sudo ufw enable
sudo ufw allow 35729/tcp