Hey everyone,
Fellow NextJS- and Netlify-fan here! ![]()
I’ve been looking for a way to bring serverless NextJS to Netlify for a while. And I’m very happy to share that I’ve found a solution! ![]()
I’ve packed that solution up into a small npm package called next-on-netlify. It’s just a compatibility wrapper for hosting NextJS apps on Netlify. Check out this Medium article on getting started in 5 quick steps.
Basically, the package does three things:
- Copy each NextJS pages into either the
publicdirectory (if it uses.getInitialPropsand does not need to be SSRed) OR thefunctionsdirectory (if it uses.getInitialPropsand does need to be SSRed) - Create a Netlify function called
nextRouterthat is responsible for server-side rendering those pages that use.getInitialProps - Set up a Netlify
_redirectsfile and proxy all requests for SSR pages to thenextRouterNetlify function
You can check out a demo here: next-on.netlify.com/
And you can check out the main script of the package here: next-on-netlify/next-on-netlify.js at master · netlify/next-on-netlify · GitHub
Let me know what you think, whether you run into any issues, any ideas for improvements, etc… And if you end up building anything with next-on-netlify, I would love to hear about it, too ![]()