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): remove the need to install @nx/next for production builds #16469

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Apr 21, 2023

This PR brings back the compiled version of the withNx function. This allows @nx/next to not be installed as a production dependency, which avoids pulling in @nx/devkit and other dev packages.

Current Behavior

@nx/next or @nrwl/next must be installed as production dependency.

Expected Behavior

@nx/next or @nrwl/next don't need to be installed for the compiled app to run.

Related Issue(s)

Fixes #15931

@vercel
Copy link

vercel bot commented Apr 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Apr 21, 2023 6:42pm

@@ -6,4 +6,4 @@ export { componentGenerator } from './src/generators/component/component';
export { libraryGenerator } from './src/generators/library/library';
export { pageGenerator } from './src/generators/page/page';
export { withNx } from './plugins/with-nx';
export { composePlugins } from './src/utils/config';
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved composePlugins to its own file so we can copy the compiled version to dist during build.

: joinPathFragments(outputDir, '.next');
} else {
return '.next';
try {
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic will only be needed when running through Nx. i.e. nx serve <app> --prod

@jaysoo jaysoo force-pushed the fix/next-remove-dependency-to-with-nx branch from 24af604 to d6f3ffa Compare April 21, 2023 17:56
}

return '.next';
Copy link
Member Author

Choose a reason for hiding this comment

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

For deployment platforms like Vercel, or a self-contained Docker image, the folder should just be .next (or whatever the user sets it to).

}

return nextConfig.distDir || '.next';
Copy link
Member Author

Choose a reason for hiding this comment

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

For Vercel and other platforms (including self-contained Docker images), use .next or whatever the user sets in their next.config.js.

};
} else {
const {
Copy link
Member Author

Choose a reason for hiding this comment

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

Inline all of the require to run only during build phase. We don't need these to production.

@jaysoo jaysoo force-pushed the fix/next-remove-dependency-to-with-nx branch 2 times, most recently from ff2eea9 to 23ba8bd Compare April 21, 2023 18:01
);
writeFileSync(join(helpersPath, 'with-nx.js'), getWithNxContent());
writeFileSync(
join(helpersPath, 'compiled.js'),
Copy link
Member Author

Choose a reason for hiding this comment

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

A smaller version of with-nx.js that does not depend on Nx packages.

@jaysoo jaysoo force-pushed the fix/next-remove-dependency-to-with-nx branch 3 times, most recently from 19cb3bd to 3a6f537 Compare April 21, 2023 18:30
@jaysoo jaysoo marked this pull request as ready for review April 21, 2023 18:30
@jaysoo jaysoo force-pushed the fix/next-remove-dependency-to-with-nx branch from 3a6f537 to 56b384f Compare April 21, 2023 18:41
@jaysoo jaysoo merged commit 564ffae into nrwl:master Apr 21, 2023
@jaysoo jaysoo deleted the fix/next-remove-dependency-to-with-nx branch April 21, 2023 20:13
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@nrwl/next: Cannot find module '@nrwl/next/plugins/with-nx'
2 participants