Unverified Commit b1f154d8 authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

misc: move entrypoints creation into webpack build step (3/6) (#45456)

During build, entrypoint creation is only useful for the webpack build
process. Since I extracted it to another file, it makes sense to also
move it there.

Note: the way the params are added sucks, this is corrected in the next
diff.


<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 85ec9c5d
......@@ -133,7 +133,7 @@ export function createPagesMapping({
}
}
interface CreateEntrypointsParams {
export interface CreateEntrypointsParams {
buildId: string
config: NextConfigComplete
envFiles: LoadedEnvFiles
......
import '../lib/setup-exception-listeners'
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import { loadEnvConfig } from '@next/env'
import chalk from 'next/dist/compiled/chalk'
import crypto from 'crypto'
......@@ -82,7 +81,7 @@ import {
} from '../telemetry/events'
import { Telemetry } from '../telemetry/storage'
import { getPageStaticInfo } from './analysis/get-page-static-info'
import { createEntrypoints, createPagesMapping } from './entries'
import { createPagesMapping } from './entries'
import { generateBuildId } from './generate-build-id'
import { isWriteable } from './is-writeable'
import * as Log from './output/log'
......@@ -149,12 +148,6 @@ export const NextBuildContext: Partial<{
telemetryPlugin: TelemetryPlugin
buildSpinner: any
nextBuildSpan: Span
entrypoints: {
client: webpack.EntryObject
server: webpack.EntryObject
edgeServer: webpack.EntryObject
middlewareMatchers: undefined
}
dir: string
}> = {}
......@@ -565,26 +558,6 @@ export default async function build(
})
}
const entrypoints = await nextBuildSpan
.traceChild('create-entrypoints')
.traceAsyncFn(() =>
createEntrypoints({
buildId,
config,
envFiles: loadedEnvFiles,
isDev: false,
pages: mappedPages,
pagesDir,
previewMode: previewProps,
rootDir: dir,
rootPaths: mappedRootPaths,
appDir,
appPaths: mappedAppPages,
pageExtensions: config.pageExtensions,
})
)
NextBuildContext.entrypoints = entrypoints
const pagesPageKeys = Object.keys(mappedPages)
const conflictingAppPagePaths: [pagePath: string, appPath: string][] = []
......@@ -947,17 +920,32 @@ export default async function build(
ignore: [] as string[],
}))
const webpackBuildDuration = await webpackBuild({
buildId,
config,
pagesDir,
reactProductionProfiling,
rewrites,
target,
appDir,
noMangling,
middlewareMatchers: entrypoints.middlewareMatchers,
})
const webpackBuildDuration = await webpackBuild(
{
buildId,
config,
pagesDir,
reactProductionProfiling,
rewrites,
target,
appDir,
noMangling,
},
{
buildId,
config,
envFiles: loadedEnvFiles,
isDev: false,
pages: mappedPages,
pagesDir,
previewMode: previewProps,
rootDir: dir,
rootPaths: mappedRootPaths,
appDir,
appPaths: mappedAppPages,
pageExtensions: config.pageExtensions,
}
)
telemetry.record(
eventBuildCompleted(pagesPaths, {
......
......@@ -15,8 +15,8 @@ import { injectedClientEntries } from './webpack/plugins/flight-client-entry-plu
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import { Rewrite } from '../lib/load-custom-routes'
import { NextConfigComplete } from '../server/config-shared'
import { MiddlewareMatcher } from './analysis/get-page-static-info'
import { NextBuildContext } from '.'
import { CreateEntrypointsParams, createEntrypoints } from './entries'
type CompilerResult = {
errors: webpack.StatsError[]
......@@ -34,21 +34,23 @@ function isTelemetryPlugin(plugin: unknown): plugin is TelemetryPlugin {
return plugin instanceof TelemetryPlugin
}
export async function webpackBuild(commonWebpackOptions: {
buildId: string
config: NextConfigComplete
pagesDir: string | undefined
reactProductionProfiling: boolean
rewrites: {
fallback: Rewrite[]
afterFiles: Rewrite[]
beforeFiles: Rewrite[]
}
target: string
appDir: string | undefined
noMangling: boolean
middlewareMatchers: MiddlewareMatcher[] | undefined
}): Promise<number> {
export async function webpackBuild(
commonWebpackOptions: {
buildId: string
config: NextConfigComplete
pagesDir: string | undefined
reactProductionProfiling: boolean
rewrites: {
fallback: Rewrite[]
afterFiles: Rewrite[]
beforeFiles: Rewrite[]
}
target: string
appDir: string | undefined
noMangling: boolean
},
entrypointsParams: CreateEntrypointsParams
): Promise<number> {
let result: CompilerResult | null = {
warnings: [],
errors: [],
......@@ -62,7 +64,10 @@ export async function webpackBuild(commonWebpackOptions: {
// IIFE to isolate locals and avoid retaining memory too long
const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler')
const entrypoints = NextBuildContext.entrypoints!
const entrypoints = await nextBuildSpan
.traceChild('create-entrypoints')
.traceAsyncFn(() => createEntrypoints(entrypointsParams))
const configs = await runWebpackSpan
.traceChild('generate-webpack-config')
.traceAsyncFn(() =>
......@@ -70,18 +75,21 @@ export async function webpackBuild(commonWebpackOptions: {
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.client,
entrypoints: entrypoints.client,
}),
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.server,
entrypoints: entrypoints.server,
}),
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.edgeServer,
entrypoints: entrypoints.edgeServer,
}),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment