Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Respect CLI output path when provided #17947

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ describe('Next.js Applications', () => {
});
}, 1_000_000);

it('should build app and .next artifacts at the outputPath if provided by the CLI', () => {
const appName = uniq('app');
runCLI(`generate @nx/next:app ${appName} --no-interactive --style=css`);

runCLI(`build ${appName} --outputPath="dist/foo"`);

checkFilesExist('dist/foo/package.json');
checkFilesExist('dist/foo/next.config.js');
// Next Files
checkFilesExist('dist/foo/.next/package.json');
checkFilesExist('dist/foo/.next/build-manifest.json');
}, 600_000);

// TODO(jack): re-enable this test
xit('should be able to serve with a proxy configuration', async () => {
const appName = uniq('app');
Expand Down
4 changes: 4 additions & 0 deletions packages/next/plugins/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ function withNx(
}
});

// process.env.NX_NEXT_OUTPUT_PATH is set when running @nx/next:build
options.outputPath =
process.env.NX_NEXT_OUTPUT_PATH || options.outputPath;

// outputPath may be undefined if using run-commands or other executors other than @nx/next:build.
// In this case, the user should set distDir in their next.config.js.
if (options.outputPath) {
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export default async function buildExecutor(
process.env['__NEXT_REACT_ROOT'] ||= 'true';
}

const { experimentalAppOnly, profile, debug } = options;
const { experimentalAppOnly, profile, debug, outputPath } = options;

// Set output path here since it can also be set via CLI
// We can retrieve it inside plugins/with-nx
process.env.NX_NEXT_OUTPUT_PATH ??= outputPath;

const args = createCliOptions({ experimentalAppOnly, profile, debug });
const command = `npx next build ${args.join(' ')}`;
Expand Down