2019-06-24 15:48:26 +02:00
|
|
|
import { loader } from 'webpack'
|
2019-01-08 23:10:32 +01:00
|
|
|
import loaderUtils from 'loader-utils'
|
|
|
|
|
|
|
|
export type ClientPagesLoaderOptions = {
|
2019-05-29 13:57:26 +02:00
|
|
|
absolutePagePath: string
|
2019-01-08 23:10:32 +01:00
|
|
|
page: string
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
const nextClientPagesLoader: loader.Loader = function() {
|
|
|
|
const { absolutePagePath, page }: any = loaderUtils.getOptions(this)
|
2019-01-08 23:10:32 +01:00
|
|
|
const stringifiedAbsolutePagePath = JSON.stringify(absolutePagePath)
|
|
|
|
const stringifiedPage = JSON.stringify(page)
|
|
|
|
|
|
|
|
return `
|
|
|
|
(window.__NEXT_P=window.__NEXT_P||[]).push([${stringifiedPage}, function() {
|
2019-09-11 19:21:10 +02:00
|
|
|
var mod = require(${stringifiedAbsolutePagePath})
|
2019-01-08 23:10:32 +01:00
|
|
|
if(module.hot) {
|
|
|
|
module.hot.accept(${stringifiedAbsolutePagePath}, function() {
|
|
|
|
if(!next.router.components[${stringifiedPage}]) return
|
|
|
|
var updatedPage = require(${stringifiedAbsolutePagePath})
|
2019-09-11 19:21:10 +02:00
|
|
|
next.router.update(${stringifiedPage}, updatedPage)
|
2019-01-08 23:10:32 +01:00
|
|
|
})
|
|
|
|
}
|
2019-09-11 19:21:10 +02:00
|
|
|
return mod
|
2019-01-08 23:10:32 +01:00
|
|
|
}]);
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
export default nextClientPagesLoader
|