2016-10-17 14:35:31 +00:00
|
|
|
import { resolve, relative } from 'path'
|
2016-10-14 15:05:08 +00:00
|
|
|
|
2016-12-02 01:43:38 +00:00
|
|
|
module.exports = function (content, sourceMap) {
|
2016-10-14 15:05:08 +00:00
|
|
|
this.cacheable()
|
|
|
|
|
2016-10-17 14:35:31 +00:00
|
|
|
const route = getRoute(this)
|
|
|
|
|
2016-12-02 01:43:38 +00:00
|
|
|
this.callback(null, `${content}
|
2016-12-06 09:24:42 +00:00
|
|
|
(function (Component, route) {
|
|
|
|
if (!module.hot) return
|
|
|
|
if (!__resourceQuery) return
|
|
|
|
|
|
|
|
var qs = require('querystring')
|
|
|
|
var params = qs.parse(__resourceQuery.slice(1))
|
|
|
|
if (params.entry == null) return
|
|
|
|
|
2016-10-14 15:05:08 +00:00
|
|
|
module.hot.accept()
|
2016-12-06 09:24:42 +00:00
|
|
|
Component.__route = route
|
2016-11-03 15:12:37 +00:00
|
|
|
|
2016-12-06 09:24:42 +00:00
|
|
|
if (module.hot.status() === 'idle') return
|
2016-11-03 15:12:37 +00:00
|
|
|
|
2016-12-06 09:24:42 +00:00
|
|
|
var components = next.router.components
|
|
|
|
for (var r in components) {
|
|
|
|
if (!components.hasOwnProperty(r)) continue
|
2016-11-03 15:12:37 +00:00
|
|
|
|
2016-12-06 09:24:42 +00:00
|
|
|
if (components[r].Component.__route === route) {
|
|
|
|
next.router.update(r, Component)
|
2016-11-03 15:12:37 +00:00
|
|
|
}
|
2016-10-14 15:05:08 +00:00
|
|
|
}
|
2017-07-10 04:40:32 +00:00
|
|
|
})(typeof __webpack_exports__ !== 'undefined' ? __webpack_exports__.default : (module.exports.default || module.exports), ${JSON.stringify(route)})
|
2016-12-02 01:43:38 +00:00
|
|
|
`, sourceMap)
|
2016-10-14 15:05:08 +00:00
|
|
|
}
|
2016-10-17 14:35:31 +00:00
|
|
|
|
2016-11-03 15:12:37 +00:00
|
|
|
const nextPagesDir = resolve(__dirname, '..', '..', '..', 'pages')
|
|
|
|
|
2016-10-17 14:35:31 +00:00
|
|
|
function getRoute (loaderContext) {
|
|
|
|
const pagesDir = resolve(loaderContext.options.context, 'pages')
|
2016-11-03 15:12:37 +00:00
|
|
|
const { resourcePath } = loaderContext
|
|
|
|
const dir = [pagesDir, nextPagesDir]
|
|
|
|
.find((d) => resourcePath.indexOf(d) === 0)
|
|
|
|
const path = relative(dir, resourcePath)
|
|
|
|
return '/' + path.replace(/((^|\/)index)?\.js$/, '')
|
2016-10-17 14:35:31 +00:00
|
|
|
}
|