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

feat(nextjs): Add support for create nodes for nextjs #20193

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

ndcunningham
Copy link
Contributor

@ndcunningham ndcunningham commented Nov 10, 2023

Current Behavior

There is no plugin to run Nextjs projects (a project containing next.config.js)

Expected Behavior

Using this plugin @nx/next/plugin inside a fresh will create targets (build, start & dev) to nx.json.
The user should now be able to run these targets without configuring a project.json.

How to Use

Add this to your nx.json plugins

  "plugins": [
    {
      "plugin": "@nx/next/plugin",
      "options": {
        "buildTargetName": "build", // <--- These names you can changed to your liking
        "startTargetName": "start",
        "devTargetName": "dev",
      }
    }
  ]

For new projects when you create a Nextjs project this will already be set up for you after passing NX_PCV3=true.

NX_PCV3=true nx generate @nx/next:app ${appName} --project-name-and-root-format=as-provided --no-interactive

NB

next export has been deprecated in favor of:

const nextConfig = {
//....... other configs

  output: 'export'
};

@ndcunningham ndcunningham self-assigned this Nov 10, 2023
Copy link

vercel bot commented Nov 10, 2023

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2023 10:44pm

@ndcunningham ndcunningham added the scope: nextjs Issues related to NextJS support for Nx label Nov 10, 2023
@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 5 times, most recently from 3f6b838 to 6af2372 Compare November 14, 2023 21:42
@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 4 times, most recently from 8a9fce4 to 04bc623 Compare November 24, 2023 20:40
@ndcunningham ndcunningham marked this pull request as ready for review November 27, 2023 18:29
@ndcunningham ndcunningham requested a review from a team as a code owner November 27, 2023 18:29
@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 6 times, most recently from d8cc774 to 3104e75 Compare November 29, 2023 18:50
@@ -94,6 +94,6 @@ describe('Next.js Webpack', () => {
expect(() => {
runCLI(`build ${appName}`);
}).not.toThrow();
checkFilesExist(`apps/${appName}/.next/build-manifest.json`);
checkFilesExist(`dist/apps/${appName}/.next/build-manifest.json`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

build only creates production artifacts so this test case was wrong before.

@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 3 times, most recently from f6d4619 to 3a76a1c Compare November 29, 2023 22:53
@ndcunningham ndcunningham requested a review from a team as a code owner November 29, 2023 22:53
@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 3 times, most recently from 605712b to ecf922a Compare November 30, 2023 17:06
@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 2 times, most recently from 322568e to 7ef5b07 Compare December 1, 2023 01:56
@jaysoo
Copy link
Member

jaysoo commented Dec 1, 2023

Added some comments. I think the rest looks fine.

@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 3 times, most recently from 2c24128 to 507a32e Compare December 4, 2023 17:41
@jaysoo
Copy link
Member

jaysoo commented Dec 4, 2023

We'll need to check what's still needed from withNx and what features require the full Nx context (task name, graph, etc.). If we can simplify the new setup we should, and leave legacy behavior for existing projects.

@ndcunningham
Copy link
Contributor Author

ndcunningham commented Dec 5, 2023

We'll need to check what's still needed from withNx and what features require the full Nx context (task name, graph, etc.). If we can simplify the new setup we should, and leave legacy behavior for existing projects.

Updated:

  • Now we don't generate .nx-helpers nor next.config.js inside dist
  • For those we will need nx context (Docker) will need require @nx/next as a prod dependency

@ndcunningham ndcunningham force-pushed the feat/next-create-nodes branch 4 times, most recently from ff10879 to 0fdf87b Compare December 6, 2023 21:46
@ndcunningham ndcunningham merged commit b8d24e6 into nrwl:master Dec 6, 2023
6 checks passed
@ndcunningham ndcunningham deleted the feat/next-create-nodes branch December 7, 2023 16:11
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 Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: nextjs Issues related to NextJS support for Nx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants