rsnext/packages/next/build/webpack/loaders/next-client-pages-loader.ts
Guy Bedford 005a8abe39
feat: Webpack loader inlining (#21127)
This picks up on the inlining work in https://github.com/vercel/next.js/pull/20598 to also include webpack loader inlining optimizations.

This includes:
* The dependencies of sass-loader
* resolve-url-loader

And for added benefit:
* babel-plugin-transform-define
* babel-plugin-transform-react-remove-prop-types

style-loader and css-loader didn't inline easily. Perhaps we can come back to these ones.
2021-01-15 01:51:45 +00:00

35 lines
1 KiB
TypeScript

import loaderUtils from 'next/dist/compiled/loader-utils'
import { tracer, traceFn } from '../../tracer'
export type ClientPagesLoaderOptions = {
absolutePagePath: string
page: string
}
// this parameter: https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters
function nextClientPagesLoader(this: any) {
return tracer.withSpan(this.currentTraceSpan, () => {
const span = tracer.startSpan('next-client-pages-loader')
return traceFn(span, () => {
const { absolutePagePath, page } = loaderUtils.getOptions(
this
) as ClientPagesLoaderOptions
span.setAttribute('absolutePagePath', absolutePagePath)
const stringifiedAbsolutePagePath = JSON.stringify(absolutePagePath)
const stringifiedPage = JSON.stringify(page)
return `
(window.__NEXT_P = window.__NEXT_P || []).push([
${stringifiedPage},
function () {
return require(${stringifiedAbsolutePagePath});
}
]);
`
})
})
}
export default nextClientPagesLoader