webxl / grunt-reload

A grunt task and reverse proxy that enables live reloading of updated files in the browser.
MIT License
132 stars 19 forks source link

[Grunt 0.3.17] reload task launches server each time & doesn't trigger refresh #23

Open cemckinley opened 11 years ago

cemckinley commented 11 years ago

Related to Issue #13

Same problem using Grunt 0.3.17 and grunt-reload 0.2 - the reload server is launched every time the reload task is run, therefore no page refresh is triggered. Unfortunately I can't upgrade to grunt 0.4 to get the updated version of the grunt-reload plugin, due to some other breakages.

I tried manually updating the reload.js task file to the 0.4 version (and installed the request dependency), and this fixes the issue except for one line that causes an undefined error - line 73:

var connectOpts = grunt.config(['connect', target]).options;

Not sure if the 'connect' config item is something new to grunt 0.4, but it's not required in my own 0.3.17 grunt file. Setting the connectOpts var to an empty object allowed the code to move on and run successfully.

I only tried the above with the proxy method, not iframe or liveReload so not sure if anything would affect those or other parts. Would love to see a fix implemented for 0.3.17 as well.

logankoester commented 11 years ago

I am also affected by this issue. Using the proxy method, I was able to work around the bug by overwriting reload.js from master (after running npm install request, a new dependency), but grunt dies when a LiveReload client connects:

/home/ldk/hack/learn/grunt-reload-bug/node_modules/grunt-reload/tasks/reload.js:198
                        grunt.event.emit('reload:' + data.command, connection)
                                    ^
TypeError: Cannot call method 'emit' of undefined
    at WebSocketConnection.module.exports.grunt.registerTask.that (/home/ldk/hack/learn
/grunt-reload-bug/node_modules/grunt-reload/tasks/reload.js:198:37)
    at WebSocketConnection.EventEmitter.emit (events.js:96:17)
    at WebSocketConnection.processFrame (/home/ldk/hack/learn/grunt-reload-bug/node_modules/grunt-
reload/node_modules/websocket/lib/WebSocketConnection.js:403:26)
    at WebSocketConnection.handleSocketData (/home/ldk/hack/learn/grunt-reload-bug/node_modules/gr
unt-reload/node_modules/websocket/lib/WebSocketConnection.js:247:14)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:396:14)