2018-03-06 11:55:03 +00:00
|
|
|
import 'event-source-polyfill'
|
2018-07-24 09:24:40 +00:00
|
|
|
import connect from './dev-error-overlay/hot-dev-client'
|
|
|
|
export default ({assetPrefix}) => {
|
|
|
|
const options = {
|
|
|
|
path: `${assetPrefix}/_next/webpack-hmr`
|
|
|
|
}
|
|
|
|
|
|
|
|
const devClient = connect(options)
|
2016-11-23 18:32:49 +00:00
|
|
|
|
2018-07-24 09:24:40 +00:00
|
|
|
devClient.subscribeToHmrEvent((obj) => {
|
2019-01-08 22:10:32 +00:00
|
|
|
if (obj.action === 'reloadPage') {
|
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
if (obj.action === 'removedPage') {
|
|
|
|
const [page] = obj.data
|
|
|
|
if (page === window.next.router.pathname) {
|
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (obj.action === 'addedPage') {
|
|
|
|
const [page] = obj.data
|
|
|
|
if (page === window.next.router.pathname && typeof window.next.router.components[page] === 'undefined') {
|
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
return
|
2017-04-18 04:18:43 +00:00
|
|
|
}
|
2019-01-08 22:10:32 +00:00
|
|
|
throw new Error('Unexpected action ' + obj.action)
|
2017-04-18 04:18:43 +00:00
|
|
|
})
|
2018-07-24 09:24:40 +00:00
|
|
|
|
|
|
|
return devClient
|
2017-04-18 04:18:43 +00:00
|
|
|
}
|