mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
24 lines
603 B
JavaScript
24 lines
603 B
JavaScript
import { resolve, relative } from 'path'
|
|
|
|
module.exports = function (content) {
|
|
this.cacheable()
|
|
|
|
const route = getRoute(this)
|
|
|
|
return content + `
|
|
if (module.hot) {
|
|
module.hot.accept()
|
|
if (module.hot.status() !== 'idle') {
|
|
var Component = module.exports.default || module.exports
|
|
next.router.update('${route}', Component)
|
|
}
|
|
}
|
|
`
|
|
}
|
|
|
|
function getRoute (loaderContext) {
|
|
const pagesDir = resolve(loaderContext.options.context, 'pages')
|
|
const path = loaderContext.resourcePath
|
|
return '/' + relative(pagesDir, path).replace(/((^|\/)index)?\.js$/, '')
|
|
}
|