All Projects → netlify → Next On Netlify

netlify / Next On Netlify

Licence: mit
Build and deploy Next.js applications with Server-Side Rendering on Netlify!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Next On Netlify

Zip It And Ship It
Intelligently prepare Node.js Lambda functions for deployment
Stars: ✭ 104 (-85.54%)
Mutual labels:  serverless, lambda-functions, netlify
Commercejs Nextjs Demo Store
Commerce demo store built for the Jamstack. Built with Commerce.js, Next.js, and can be one-click deployed to Netlify. Includes product catalog, categories, variants, cart, checkout, payments (Stripe) order confirmation, and printable receipts.
Stars: ✭ 737 (+2.5%)
Mutual labels:  serverless, netlify, nextjs
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (-59.39%)
Mutual labels:  nextjs, server-side-rendering
Jamstackthemes
A list of themes and starters for JAMstack sites.
Stars: ✭ 298 (-58.55%)
Mutual labels:  netlify, nextjs
Next Server Components
Experimental demo of React Server Components with Next.js. Deployed serverlessly on Vercel.
Stars: ✭ 444 (-38.25%)
Mutual labels:  serverless, nextjs
Create Next App
Create Next.js apps in one command
Stars: ✭ 2,783 (+287.07%)
Mutual labels:  nextjs, server-side-rendering
React Storefront
Build and deploy e-commerce progressive web apps (PWAs) in record time.
Stars: ✭ 275 (-61.75%)
Mutual labels:  nextjs, server-side-rendering
Eleventyone
A scaffold for a quick start building with the Eleventy SSG
Stars: ✭ 390 (-45.76%)
Mutual labels:  serverless, netlify
nextjs-blog-starter-kit
NextJS Blog + Contentful Typescript Starter kit with Static Export 🚀
Stars: ✭ 56 (-92.21%)
Mutual labels:  nextjs, netlify
Firebase Gcp Examples
🔥 Firebase app architectures, languages, tools & some GCP things! React w Next.js, Svelte w Sapper, Cloud Functions, Cloud Run.
Stars: ✭ 470 (-34.63%)
Mutual labels:  serverless, nextjs
Functions
Tutorials, examples, workshops and a playground for serverless with Netlify Functions
Stars: ✭ 463 (-35.61%)
Mutual labels:  serverless, netlify
Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+577.19%)
Mutual labels:  serverless, lambda-functions
nativesintech.org
The repository for the Natives in Tech website
Stars: ✭ 37 (-94.85%)
Mutual labels:  nextjs, netlify
next-saga-example
Example of using next.js with redux saga
Stars: ✭ 24 (-96.66%)
Mutual labels:  nextjs, server-side-rendering
Serverless Plugin Canary Deployments
Canary deployments for your Serverless application
Stars: ✭ 283 (-60.64%)
Mutual labels:  serverless, lambda-functions
web-starter-kit
An opinionated starter kit with styled-system, graphql-hooks, mobx and nextjs (PWA)
Stars: ✭ 17 (-97.64%)
Mutual labels:  nextjs, server-side-rendering
Serverless Photo Recognition
A collection of 3 lambda functions that are invoked by Amazon S3 or Amazon API Gateway to analyze uploaded images with Amazon Rekognition and save picture labels to ElasticSearch (written in Kotlin)
Stars: ✭ 345 (-52.02%)
Mutual labels:  serverless, lambda-functions
Awesome Nextjs
📔 📚 A curated list of awesome resources : books, videos, articles about using Next.js (A minimalistic framework for universal server-rendered React applications)
Stars: ✭ 6,812 (+847.43%)
Mutual labels:  nextjs, server-side-rendering
server-authentication-next.js
No description or website provided.
Stars: ✭ 103 (-85.67%)
Mutual labels:  nextjs, server-side-rendering
next-utils
🥩 🍳 A set of Next.js HoC utilities to make your life easier
Stars: ✭ 30 (-95.83%)
Mutual labels:  nextjs, server-side-rendering

Deprecating next-on-netlify

We are deprecating next-on-netlify in favor of Netlify's Essential Next.js Build Plugin. Please visit this issue to learn more about the deprecation of next-on-netlify and ask any questions. You can also visit our simple Migration doc for assistance migrating to the plugin.

Next.js on Netlify

next-on-netlify is a utility for enabling server-side rendering in Next.js on Netlify. It wraps your application in a tiny compatibility layer, so that pages can use Netlify Functions to be server-side rendered.

Table of Contents

Installation

npm install --save next-on-netlify

Setup

1. Set Next.js target to serverless

We must build our Next.js app as a serverless app. You can read more about serverless Next.js here.

It's super simple. Just create a next.config.js file in the root of your project and write the following:

// next.config.js

module.exports = {
  // Target must be serverless
  target: "serverless",
};

If binaries are needed in the deployment the following configuration is needed (Prisma is an example):

// next.config.js

module.exports = {
  // Target must be experimental-serverless-trace
  // Your build time will be longer with this option
  target: "experimental-serverless-trace",
};

2. Add postbuild hook

The next-on-netlify package adds the next-on-netlify command. When we run this command, some magic happens to prepare our Next.js app for hosting on Netlify*.

We want the next-on-netlify command to run after we build our Next.js application. So let's add a postbuild hook to our package.json file. You should add "postbuild": "next-on-netlify" to the existing scripts, like so:

{
  "name": "my-nextjs-app",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "postbuild": "next-on-netlify"
  },
  ...
}

*If you're curious about the "magic", check out the well-documented next-on-netlify.js file.

3. Configure for Netlify

We're almost done! We just have to tell Netlify how to build our Next.js app, where the functions folder is located, and which folder to upload to its CDN. We do that with a netlify.toml file in the root of your project and the following instructions:

[build]
  command   = "npm run build"
  functions = "out_functions"
  publish   = "out_publish"

Note: out_functions and out_publish are hard-coded into next-on-netlify. These are not configurable at the moment.

(Optional) Configure private git submodules

If your project contains private submodules, in order to deploy it, you will need to:

  1. Generate a Deploy Key in Netlify and add it to the relevant submodules so that they can be cloned during the deploy process.

  2. Ensure the submodule remotes are set to SSH format (i.e. [email protected]:owner/project.git, not https://...). Inside the submodule directory, the git remote can be updated with:

    # git remote set-url [remote] [url]
    git remote set-url origin [email protected]:owner/project.git
    

We're done. Let's deploy 🚀🚀🚀

If you're not familiar with Netlify, follow the deployment instructions here: https://www.netlify.com/blog/2020/11/30/how-to-deploy-next.js-sites-to-netlify/

Demo

Optional Extras

Preview Locally

I recommend you still use next dev to build and preview your application locally.

But if you want to emulate the Netlify deployment on your computer, you can also run next-on-netlify locally and then use netlify-cli to preview the result.

First, install the latest version of netlify-cli (you can also look at package.json to see the version that next-on-netlify has been tested against):

npm install -g netlify-cli

Then, add the following [dev] block to your netlify.toml:

# netlify.toml

# [build]
#   ...

[dev]
  functions = "out_functions"
  publish   = "out_publish"
  # We manually set the framework to static, otherwise Netlify automatically
  # detects Next.js and redirects do not work.
  # Read more: https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection
  framework = "#static"

Lastly, add the following lines to your .gitignore:

# .gitignore

# Files generated by next-on-netlify command
/out_publish/
/out_functions/

Now you're all set.

From now on, whenever you want to preview your application locally, just run:

  1. npx next-on-netlify watch: This will run next build to build your Next.js app and next-on-netlify to prepare your Next.js app for compatibility with Netlify. Any source code changes will trigger another build.
  2. netlify dev: This will emulate Netlify on your computer and let you preview your app on http://localhost:8888.

Note:

Preview Mode is not yet available locally, running netlify dev, for static pages without revalidate or fallback. This will be supported soon.

For now, Preview Mode is supported in production for all Next.js page types.

Custom Netlify Redirects

You can define custom redirects in a _redirects and/or in your netlify.toml file. The precedence of these rules are:

  • _redirects
  • next-on-netlify redirects

Currently, there is no support for redirects set in your netlify.toml file.

Read more about Netlify redirects here.

Custom Netlify Functions

next-on-netlify creates one Netlify Function for each of your SSR pages and API endpoints. Currently, you can only create custom Netlify functions using @netlify/plugin-nextjs.

Background Functions

If your Next.js API page/route ends in -background, it will be treated as a Netlify background function. Note: background functions are only available on certain plans.

Using Netlify Identity

You can use Netlify Identity with next-on-netlify. For all pages with server-side rendering (getInitialProps*, getServerSideProps, and API routes), you can access the clientContext object via the req parameter.

For example:

const Page = () => <p>Hello World!</p>;

export const getServerSideProps = async ({ req }) => {
  // Get event and context from Netlify Function
  const {
    netlifyFunctionParams: { event, context },
  } = req;

  // Access Netlify identity
  const { identity, user } = context.clientContext;

  return {
    props: {},
  };
};

export default Page;

To access Netlify Identity from pages without server-side rendering, you can create a Next API route that performs identity-related logic:

export default async function getUser(req, res) {
  // Get event and context from Netlify Function
  const {
    netlifyFunctionParams: { event, context },
  } = req;

  // Access Netlify identity
  const { user } = context.clientContext;

  // Respond with user object
  res.json({ user });
}

* Note that pages using getInitialProps are only server-side rendered on initial page load and not when the user navigates client-side between pages.

Caveats

Fallbacks for Pages with getStaticPaths

Fallback pages behave differently with next-on-netlify than they do with Next.js. On Next.js, when navigating to a path that is not defined in getStaticPaths, it first displays the fallback page. Next.js then generates the HTML in the background and caches it for future requests.

With next-on-netlify, when navigating to a path that is not defined in getStaticPaths, it server-side renders the page and sends it directly to the user. The user never sees the fallback page. The page is not cached for future requests.

For more on this, see: Issue #7

next/image

Our existing solution for next/image is not very performant. We have performance improvements on our roadmap, dependent on internal work.

To get better performance now, we recommend using a cloud provider like Cloudinary (see the Next.js docs).

Credits

This package is maintained by Lindsay Levine, Finn Woelm, and Cassidy Williams.

📣 Shoutout to @mottox2 (a pioneer of hosting Next.js on Netlify) and @danielcondemarin (author of serverless-next.js for AWS). The two were big inspirations for this package.

🙌 Big "thank you" to the following people for their contributions, support, and beta testing:

Showcase

The following sites are built with next-on-netlify:

opinionatedreact.com
opinionatedreact.com (via Twitter)

missionbit.org
missionbit.org (#18)

gemini.com

gemini.com

bigbinary.com

bigbinary.com

next-cms-ghost

Create your own blog and deploy to Netlify!

Are you building something awesome with next-on-netlify? 🔥 Let us know and we will feature it here :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].