MCPcopy
hub / github.com/vercel/next.js / exportAppImpl

Function exportAppImpl

packages/next/src/export/index.ts:191–1045  ·  view source on GitHub ↗
(
  dir: string,
  options: Readonly<ExportAppOptions>,
  span: Span,
  staticWorker?: StaticWorker
)

Source from the content-addressed store, hash-verified

189}
190
191async function exportAppImpl(
192 dir: string,
193 options: Readonly<ExportAppOptions>,
194 span: Span,
195 staticWorker?: StaticWorker
196): Promise<ExportAppResult | null> {
197 dir = resolve(dir)
198
199 // attempt to load global env values so they are available in next.config.js
200 span.traceChild('load-dotenv').traceFn(() => loadEnvConfig(dir, false, Log))
201
202 const { enabledDirectories } = options
203
204 const nextConfig =
205 options.nextConfig ||
206 (await span.traceChild('load-next-config').traceAsyncFn(() =>
207 loadConfig(PHASE_EXPORT, dir, {
208 debugPrerender: options.debugPrerender,
209 })
210 ))
211
212 const distDir = join(dir, nextConfig.distDir)
213 const telemetry = options.buildExport ? null : new Telemetry({ distDir })
214
215 if (telemetry) {
216 telemetry.record(
217 eventCliSession(nextConfig, {
218 webpackVersion: null,
219 cliCommand: 'export',
220 isSrcDir: null,
221 hasNowJson: !!(await findUp('now.json', { cwd: dir })),
222 isCustomServer: null,
223 turboFlag: false,
224 pagesDir: null,
225 appDir: null,
226 })
227 )
228 }
229
230 const subFolders = nextConfig.trailingSlash && !options.buildExport
231
232 if (!options.silent && !options.buildExport) {
233 Log.info(`using build directory: ${distDir}`)
234 }
235
236 const buildIdFile = join(distDir, BUILD_ID_FILE)
237
238 if (!existsSync(buildIdFile)) {
239 throw new ExportError(
240 `Could not find a production build in the '${distDir}' directory. Try building your app with 'next build' before starting the static export. https://nextjs.org/docs/messages/next-export-no-build-id`
241 )
242 }
243
244 const customRoutes = (['rewrites', 'redirects', 'headers'] as const).filter(
245 (config) => typeof nextConfig[config] === 'function'
246 )
247
248 if (!hasNextSupport && !options.buildExport && customRoutes.length > 0) {

Callers 1

exportAppFunction · 0.85

Calls 15

loadEnvConfigFunction · 0.90
joinFunction · 0.90
eventCliSessionFunction · 0.90
isAPIRouteFunction · 0.90
isAppPageRouteFunction · 0.90
recursiveCopyFunction · 0.90
denormalizePagePathFunction · 0.90
normalizePagePathFunction · 0.90
getPagePathFunction · 0.90
isAppRouteRouteFunction · 0.90

Tested by

no test coverage detected