forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pages Module Transition (vercel#49962)
This serves to create the loader that will allow us to transition more of the rendering logic into each of the bundled entrypoints. This only applies to pages routes inside the `pages/` folder in the node environment. fix NEXT-985 --------- Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
Showing
8 changed files
with
176 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/next/src/build/webpack/loaders/next-route-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { webpack } from 'next/dist/compiled/webpack/webpack' | ||
|
||
import { stringify } from 'querystring' | ||
import { getModuleBuildInfo } from './get-module-build-info' | ||
|
||
/** | ||
* The options for the route loader. | ||
*/ | ||
type RouteLoaderOptions = { | ||
/** | ||
* The page name for this particular route. | ||
*/ | ||
page: string | ||
|
||
/** | ||
* The preferred region for this route. | ||
*/ | ||
preferredRegion: string | string[] | undefined | ||
|
||
/** | ||
* The absolute path to the userland page file. | ||
*/ | ||
absolutePagePath: string | ||
} | ||
|
||
/** | ||
* Returns the loader entry for a given page. | ||
* | ||
* @param query the options to create the loader entry | ||
* @returns the encoded loader entry | ||
*/ | ||
export function getRouteLoaderEntry(query: RouteLoaderOptions): string { | ||
return `next-route-loader?${stringify(query)}!` | ||
} | ||
|
||
/** | ||
* Handles the `next-route-loader` options. | ||
* @returns the loader definition function | ||
*/ | ||
const loader: webpack.LoaderDefinitionFunction<RouteLoaderOptions> = | ||
function () { | ||
const { page, preferredRegion, absolutePagePath } = this.getOptions() | ||
|
||
// Ensure we only run this loader for as a module. | ||
if (!this._module) { | ||
throw new Error('Invariant: expected this to reference a module') | ||
} | ||
|
||
// Attach build info to the module. | ||
const buildInfo = getModuleBuildInfo(this._module) | ||
buildInfo.route = { | ||
page, | ||
absolutePagePath, | ||
preferredRegion, | ||
} | ||
|
||
return ` | ||
// Next.js Route Loader | ||
export * from ${JSON.stringify(absolutePagePath)} | ||
export { default } from ${JSON.stringify(absolutePagePath)} | ||
` | ||
} | ||
|
||
export default loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isInternalPathname(pathname: string): boolean { | ||
return pathname.startsWith('next/dist/pages/') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters