1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/build/loaders/hot-self-accept-loader.js
2016-10-19 21:41:45 +09:00

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$/, '')
}