rsnext/packages/next/build/webpack/loaders/next-client-pages-loader.ts

27 lines
665 B
TypeScript
Raw Normal View History

import { loader } from 'webpack'
import loaderUtils from 'loader-utils'
export type ClientPagesLoaderOptions = {
absolutePagePath: string
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(
this
) as ClientPagesLoaderOptions
const stringifiedAbsolutePagePath = JSON.stringify(absolutePagePath)
const stringifiedPage = JSON.stringify(page)
return `
(window.__NEXT_P = window.__NEXT_P || []).push([
${stringifiedPage},
function () {
2020-05-15 20:14:44 +02:00
return require(${stringifiedAbsolutePagePath});
}
]);
`
}
export default nextClientPagesLoader