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
|
|
|
|
}
|
|
|
|
|
2020-05-18 21:24:37 +02:00
|
|
|
const nextClientPagesLoader: loader.Loader = function () {
|
2020-05-15 20:14:44 +02:00
|
|
|
const { absolutePagePath, page } = loaderUtils.getOptions(
|
2020-04-18 04:19:37 +02:00
|
|
|
this
|
|
|
|
) as ClientPagesLoaderOptions
|
2019-01-08 23:10:32 +01:00
|
|
|
const stringifiedAbsolutePagePath = JSON.stringify(absolutePagePath)
|
|
|
|
const stringifiedPage = JSON.stringify(page)
|
|
|
|
|
|
|
|
return `
|
2020-04-18 04:19:37 +02:00
|
|
|
(window.__NEXT_P = window.__NEXT_P || []).push([
|
|
|
|
${stringifiedPage},
|
|
|
|
function () {
|
2020-05-15 20:14:44 +02:00
|
|
|
return require(${stringifiedAbsolutePagePath});
|
2019-01-08 23:10:32 +01:00
|
|
|
}
|
2020-04-18 04:19:37 +02:00
|
|
|
]);
|
2019-01-08 23:10:32 +01:00
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
export default nextClientPagesLoader
|