2016-10-17 14:35:31 +00:00
|
|
|
import { resolve, relative } from 'path'
|
2016-10-14 15:05:08 +00:00
|
|
|
|
|
|
|
module.exports = function (content) {
|
|
|
|
this.cacheable()
|
|
|
|
|
2016-10-17 14:35:31 +00:00
|
|
|
const route = getRoute(this)
|
|
|
|
|
2016-10-14 15:05:08 +00:00
|
|
|
return content + `
|
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept()
|
2016-10-19 12:41:45 +00:00
|
|
|
if (module.hot.status() !== 'idle') {
|
|
|
|
var Component = module.exports.default || module.exports
|
2016-10-17 14:35:31 +00:00
|
|
|
next.router.update('${route}', Component)
|
2016-10-14 15:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
2016-10-17 14:35:31 +00:00
|
|
|
|
|
|
|
function getRoute (loaderContext) {
|
|
|
|
const pagesDir = resolve(loaderContext.options.context, 'pages')
|
|
|
|
const path = loaderContext.resourcePath
|
|
|
|
return '/' + relative(pagesDir, path).replace(/((^|\/)index)?\.js$/, '')
|
|
|
|
}
|