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
Next JS: automatically copy public folder on running nx build myApp #3019
Comments
+1 for both points you've raised. There's no much point of an automatically generated package.json if it doesn't contain all the dependencies of the project that's been built. Ideally, a vendor chunk should be generated so then all it's required is to just start next and not install anything else. Especially useful for artifact deployment. |
Thanks. I would add that I've tried generating a brand new next js app and noticed that the "public" folder is not called "public" at all, it's named "assets". For consistency I would suggest naming it "public" as explained here https://nextjs.org/docs/basic-features/static-file-serving. Also (I know I'm being very very picky here but I feel this point is also important) I have tested deploying to zeit vercel (the official next js hosting platform) and must confirm that it doesn't work. The reason is that now cli ignores the local .next folder on commit. It's designed to build on the cloud but we know we can't do that due to our shared lib structure in nx (and we're not going to push all of the monorepo to zeit right?we want to just push the dist/apps/myApp built artifacts). I've raised this question here to them: https://twitter.com/code_tank_dev/status/1261752786213101570?s=19 So to recap:
This would make support super strong! |
This PR implemented generating a Identifying what packages are actually being required within the app (which I don't think is that far out there compared to some of the magic the nx tool is capable of?) would be the perfect solution, picking up the version from the root |
I do believe |
The reason |
As far as I could see, the next builder doesn’t package the vendor libraries separately but rather expecting them on start. Is there a way to tell Next to create a separate chunk with dependencies? |
I don't think next does it like that, since it seems to assume the packages will be available in |
Here is where things get tricky. Not all of those packages are needed to run your next project from dist/myApp. At least not the ones needed at build time, it's a bit like the concept behind We also need to be careful with two things:
-what happens when u try to upload to Zeit Now (I have a separate issue open for this), since the built .next folder cannot be committed. Zeit Now requires to build on their platform to be able to take advantage of all |
That's very interesting if that's the case. I don't have that much experience with Next.js, but I tried bootstrapping a new Next.js app locally then..
There seem to be 2 separate discussions here:
Let's keep this issue focused on 1. please - copying the If we think 2. is a problem, can you please create another issue with a repo with an example |
I agree...numver 1 (copy public folder) is the priority. I'll also work on a test project and create a separate issue. Tx. |
Hi @asherccohen, do you have a repo where we can see the bug? I created an app that display a single jpeg, and the assets seem to load fine with both static and ssr server. |
Oh!I might know why this is happening without sending you a repo. You are naming the "public" folder as "assets" so I guess your builder will try to copy this folder instead of "public". Naming convention in next.js apps for the static/assets/public folder is "public". |
Ah, I got it. Thanks for the clarification! |
PR for the fix is open, should be in the next patch release. |
Superb!thank you so much! |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Expected Behavior
Upon running nx build myApp for a next js project all public folder should be copied to target dist folder. Nx 9.3 has made changes to the builder but didn't introduce this and we're forced to do it manually.
Would also be super cool (but unsure how could this work) to be able to populate package.json with proper dependencies from the specific project. Is there a way to check what deps the projects needs and copy these from the root package.json? This is not a blocker if it's impossible.
Current Behavior
Public folder is not copied and we have to remember to do it manually which can be a barrier for new starters.
Failure Information (for bugs)
@jaysoo can help with this as he has implemented the builder.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: