auto-reload-brunch
Version:
Adds automatic browser reloading support to brunch.
36 lines (31 loc) • 1.18 kB
text/coffeescript
sysPath = require 'path'
WebSocketServer = (require 'ws').Server
module.exports = class AutoReloader
brunchPlugin: yes
constructor: () ->
if .autoReload
console.warn 'Warning: config.autoReload is deprecated, please move it to config.plugins.autoReload'
= .persistent and not .optimize
= []
if
cfg = .plugins?.autoReload ? .autoReload ? {}
port = cfg.port ? 9485
= new WebSocketServer host: '0.0.0.0', port: port
.on 'connection', (connection) =>
.push connection
connection.on 'close', =>
.splice connection, 1
onCompile: (changedFiles) =>
return unless
allCss = (changedFiles.length > 0) and (changedFiles.every (file) -> file.type is 'stylesheet')
message = if allCss then 'stylesheet' else 'page'
.filter (connection) =>
connection.readyState is 1
.forEach (connection) =>
connection.send message
include: ->
if
[(sysPath.join __dirname, '..', 'vendor', 'auto-reload.js')]
else
[]