Skip to content

Commit

Permalink
feat(nextjs): Add --turbo support (#17069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored May 18, 2023
1 parent 9fc99c6 commit 8ce9606
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/generated/packages/next/executors/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
18 changes: 18 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ 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 port = 4000;
const selfContainedProcess = await runCommandUntil(
`run ${appName}:serve --port=${port} --turbo`,
(output) => {
return output.includes(`TURBOPACK`);
}
);
selfContainedProcess.kill();
await killPorts();
}, 300_000);
});

function getData(port, path = ''): Promise<any> {
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/executors/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface NextServeBuilderOptions {
proxyConfig?: string;
buildLibsFromSource?: boolean;
keepAliveTimeout?: number;
turbo?: boolean;
}

export interface NextExportBuilderOptions {
Expand Down

1 comment on commit 8ce9606

@vercel
Copy link

@vercel vercel bot commented on 8ce9606 May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.