-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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): support building and serving production server #2792
Conversation
3be31d7
to
186e4d4
Compare
dc49c9b
to
0d7b386
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me.
Are you missing a test for the createPackageJson
function though? Something in the e2e tests, maybe?
0d7b386
to
942fe51
Compare
942fe51
to
0fa9a33
Compare
Very keen to try this out and I notice it was excluded from |
It will be included in the next minor release, you can try it out on |
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. |
This PR adds the ability to build a build a Next.js app that can be served locally, as well as easily deployable to platforms that support Node.
Why?
If you want proper SSR then the
dist/apps/myapp
folder must follow normal convention (e.g. have a.next
folder, etc.). And there must be apackage.json
file that contains all the necessary deps. We also need a builder for running the compiled app in production mode.Changes
Changed output folder structure for
@nrwl/next:build
so that it has a.next
folder andpackage.json
file with correct dependencies. The package versions are read out from workspacepackage.json
file.Renamed
@nrwl/next:dev-server
to@nrwl/next:server
because it is meant to run the app for production as well.The
server
builder no longer runs abuild
automatically before serving. Instead we will display an error message that follows the Next error message (e.g.Could not start production server. Try building your app with 'nx build my-app'.
)Removed
environment.ts
from being generate by app schematic, as well as the correspondingfileReplacements
entry forbuild
-- the understanding is thebuild
is always for production so you'd never donx build myapp --prod
. Usually React devs useNODE_ENV
to maintain different configurations.Example
This will start the prod server and listen on
0.0.0.0:3000
. I've also verified that the compiled app in dist can be deployed to Heroku (see: https://hackmd.io/US2eky6lSMecuHxegFZCbA?view).