From 6cfa16ff966c8e8d14257ab2d7f4736263471305 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Wed, 17 May 2023 11:56:26 -0600 Subject: [PATCH] feat(nextjs): Add --turbo support --- docs/generated/packages/next/executors/server.json | 4 ++++ e2e/next/src/next.test.ts | 11 +++++++++++ packages/next/src/executors/server/schema.json | 4 ++++ packages/next/src/executors/server/server.impl.ts | 6 ++++-- packages/next/src/utils/types.ts | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/generated/packages/next/executors/server.json b/docs/generated/packages/next/executors/server.json index eedb9c624d9afb..89cb9f2220a9b7 100644 --- a/docs/generated/packages/next/executors/server.json +++ b/docs/generated/packages/next/executors/server.json @@ -57,6 +57,10 @@ "keepAliveTimeout": { "type": "number", "description": "Max milliseconds to wait before closing inactive connection." + }, + "turbo": { + "type": "boolean", + "description": "Activate the incremental bundler for Next.js, which is implemented in Rust. Please note, this feature is exclusively available in development mode." } }, "required": ["buildTarget"], diff --git a/e2e/next/src/next.test.ts b/e2e/next/src/next.test.ts index fa9416ed026cb0..d05e8dde8c85e6 100644 --- a/e2e/next/src/next.test.ts +++ b/e2e/next/src/next.test.ts @@ -463,6 +463,17 @@ describe('Next.js Applications', () => { checkExport: false, }); }, 300_000); + + it('should support --turbo to enable Turbopack', async () => { + const appName = uniq('app'); + + runCLI( + `generate @nx/next:app ${appName} --style=css --appDir --no-interactive` + ); + + const result = runCLI(`serve ${appName}`); + expect(result).toContain('>>> TURBOPACK (beta)'); + }, 300_000); }); function getData(port, path = ''): Promise { diff --git a/packages/next/src/executors/server/schema.json b/packages/next/src/executors/server/schema.json index 8e82a96d05460b..8d8e7cc2e0a272 100644 --- a/packages/next/src/executors/server/schema.json +++ b/packages/next/src/executors/server/schema.json @@ -54,6 +54,10 @@ "keepAliveTimeout": { "type": "number", "description": "Max milliseconds to wait before closing inactive connection." + }, + "turbo": { + "type": "boolean", + "description": "Activate the incremental bundler for Next.js, which is implemented in Rust. Please note, this feature is exclusively available in development mode." } }, "required": ["buildTarget"] diff --git a/packages/next/src/executors/server/server.impl.ts b/packages/next/src/executors/server/server.impl.ts index 99d658670c1dd7..b13d5951a00f87 100644 --- a/packages/next/src/executors/server/server.impl.ts +++ b/packages/next/src/executors/server/server.impl.ts @@ -43,10 +43,12 @@ export default async function* serveExecutor( const { port, keepAliveTimeout, hostname } = options; const args = createCliOptions({ port, keepAliveTimeout, hostname }); - const nextDir = resolve(context.root, buildOptions.outputPath); - const command = `npx next ${options.dev ? `dev ${args}` : `start ${args}`}`; + const nextDir = resolve(context.root, buildOptions.outputPath); + const mode = options.dev ? 'dev' : 'start'; + const turbo = options.turbo && options.dev ? '--turbo' : ''; + const command = `npx next ${mode} ${args} ${turbo}`; yield* createAsyncIterable<{ success: boolean; baseUrl: string }>( ({ done, next, error }) => { // Client to check if server is ready. diff --git a/packages/next/src/utils/types.ts b/packages/next/src/utils/types.ts index 211db13b4b69a3..b9231089f7fa3c 100644 --- a/packages/next/src/utils/types.ts +++ b/packages/next/src/utils/types.ts @@ -53,6 +53,7 @@ export interface NextServeBuilderOptions { proxyConfig?: string; buildLibsFromSource?: boolean; keepAliveTimeout?: number; + turbo?: boolean; } export interface NextExportBuilderOptions {