R
Railway10mo ago
Dill

How to reduce Next.js build times??

Takes about 5-8 minutes to build and deploy now which is annyoing. Also increases every week
No description
No description
25 Replies
Percy
Percy10mo ago
Project ID: 030a956c-af55-4f43-a7de-5bdff4ea474b
Dill
DillOP10mo ago
030a956c-af55-4f43-a7de-5bdff4ea474b im not using any configuration btw, just default nix packs
Medim
Medim10mo ago
Besides code-wise and file excluding optimization I don't think u can do much But iirc railway caches build so your next build may be faster (I can be wrong on this one)
Dill
DillOP10mo ago
why are vercel builds so much faster though?
Brody
Brody10mo ago
vercel made next
Medim
Medim10mo ago
Well, they literally created nextjs And use "specific technologies" for it
Brody
Brody10mo ago
in turn, railway is not hyper optimized for any one specific type of app
Dill
DillOP10mo ago
this is not very helpful tbh i would appreciate if you woulr rather direct me towards resources towards optimizing nixpacks for next.js
Pepijn
Pepijn10mo ago
Just to chip in, in my case Vercel is actually slower in a fresh build, haha (using Next 14). But in Railway you have overhead which Vercel does not have? (or maybe less) due to the creating and publishing the image is to registry after which it can be deployed.
No description
Pepijn
Pepijn10mo ago
Additionally publishing the image (2.6GB) took around 3-4 mins
Adam
Adam10mo ago
Optimizing nixpacks is not the way to go. Instead, creating your own dockerfile will likely be faster. We cannot help you with that here as it does not fall under the scope of “Platform Help” you’ll have to research for yourself
Dill
DillOP10mo ago
Thanks for this direction! Will try this 🙂 thanks again @Adam made my own optimized dockerfile and build time cut by 50%
Dill
DillOP10mo ago
GitHub
next.js/examples/with-docker/Dockerfile at canary · vercel/next.js
The React Framework. Contribute to vercel/next.js development by creating an account on GitHub.
Pepijn
Pepijn10mo ago
Thanks, also interesting going this way reduced idle memory usage with 80%
pandas
pandas9mo ago
yeah docker is not comparable to railway internal system to build stuff, docker is faster easier and uses less memory
Brody
Brody9mo ago
docker is used to build the final image no matter what build system you choose to use, so that's not completely correct
Dill
DillOP9mo ago
Yep! My memory usage decreased significantly @Pepijn Build times went from 12min -> 6min Memory usage also cut in half or so meaning costs are lower Noticed the default nixpacks docker image for node is ubuntu instead of something like node-alpine? Any reason why? Cc @Brody
Brody
Brody9mo ago
so apt packages can be installed
macwilko
macwilko9mo ago
Just throwing this in here:
macwilko
macwilko9mo ago
Remix - Build Better Websites
Remix is a full stack web framework that lets you focus on the user interface and work back through web standards to deliver a fast, slick, and resilient user experience. People are gonna love using your stuff.
macwilko
macwilko9mo ago
imo it's better than next.js , you get a very similar benefit (SSR, React full stack) it runs well anywhere (including Railway.app) mem cost is great (idles about 25mb) my build time is about 2 minutes
Pepijn
Pepijn9mo ago
For comparison, after changing the NextJs build with the setup per above (including building NextJs with standalone option), my builds are also about 2 minutes for an ecommerce site connected to MedusaJs and Strapi. Memory usage in idle is around 40Mb.
pandas
pandas9mo ago
fully agree on this and if you deploy it on cloudflare you will see blazing speeds never seen before
No description
pandas
pandas9mo ago
global servers across 200 countries, can handle insane traffic, 10x cheaper than almost anyone else
Brody
Brody9mo ago
did you forget you where in the railway server? we shill railway here
Want results from more Discord servers?
Add your server